pub struct Point {
pub timestamp: i64,
}
Expand description
Point in Time
This is simply a timestamp according to UNIX convention, that is, the number of seconds since 1970-01-01 00:00:00. Negative values represent time before that epoch, obviously.
Because it is an i64
, the date range that can be represented is very large, roughly from the year -292_277_022_657
to +292_277_026_596
.
However, working with Point
s close to end of this range is a bad idea, as date math operations might overflow.
Note that the calendar time counterpart to this, DateTime
, can represent an even larger range, since it has an entire i64
for just the year.
Fields§
§timestamp: i64
Count of seconds since 1970-01-01 00:00:00
Implementations§
Source§impl Point
impl Point
Sourcepub const MIN: Self
pub const MIN: Self
The earliest Point
that can be represented by the timestamp
-292277022657-01-27 08:29:52
(a Monday)
Sourcepub const MAX: Self
pub const MAX: Self
The last Point
that can be represented by the timestamp
292277026596-12-04 15:30:07
(a Sunday)
Sourcepub const fn from_epoch(timestamp: i64) -> Self
pub const fn from_epoch(timestamp: i64) -> Self
Same as constructing Point {timestamp}
directly
Sourcepub const fn checked_add(self, span: Span) -> Option<Self>
pub const fn checked_add(self, span: Span) -> Option<Self>
Checked Span
addition
Computes self + span
, returning None
if overflow occurred.
use greg::{Point, Span};
assert_eq!(
Point::now().checked_add(Span::parse("300000000000y")),
None
);
assert_eq!(
Point::MIN.checked_add(Span::MAX),
Some(Point::MAX)
);
Sourcepub const fn checked_sub(self, span: Span) -> Option<Self>
pub const fn checked_sub(self, span: Span) -> Option<Self>
Checked Span
subtraction
Computes self - span
, returning None
if overflow occurred.
use greg::{Point, Span};
assert_eq!(
Point::now().checked_sub(Span::parse("300000000000y")),
None
);
assert_eq!(
Point::MAX.checked_sub(Span::MAX),
Some(Point::MIN)
);
Sourcepub const fn saturating_add(self, span: Span) -> Self
pub const fn saturating_add(self, span: Span) -> Self
Saturating Span
addition
Computes self + span
, saturating at the numeric bounds instead of overflowing.
use greg::{Point, Span};
assert_eq!(
Point::now().saturating_add(Span::parse("300000000000y")),
Point::MAX
);
assert_eq!(
Point::MIN.saturating_add(Span::MAX - Span::SECOND),
Point::MAX - Span::SECOND
);
Sourcepub const fn saturating_sub(self, span: Span) -> Self
pub const fn saturating_sub(self, span: Span) -> Self
Saturating Span
subtraction
Computes self - span
, saturating at the numeric bounds instead of overflowing.
use greg::{Point, Span};
assert_eq!(
Point::now().saturating_sub(Span::parse("300000000000y")),
Point::MIN
);
assert_eq!(
Point::MAX.saturating_sub(Span::MAX - Span::SECOND),
Point::MIN + Span::SECOND
);
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Point
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Point
serde
only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<SystemTime> for Point
impl From<SystemTime> for Point
Source§fn from(sys: SystemTime) -> Self
fn from(sys: SystemTime) -> Self
Source§impl FromSql for Point
Available on crate feature rusqlite
only.
impl FromSql for Point
rusqlite
only.Source§fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>
Source§impl Ord for Point
impl Ord for Point
Source§impl PartialOrd for Point
impl PartialOrd for Point
Source§impl ToSql for Point
Available on crate feature rusqlite
only.
impl ToSql for Point
rusqlite
only.