pub struct DateTime { /* private fields */ }Expand description
A civil time of a day on a particular Gregorian date.
Implementations§
Source§impl DateTime
impl DateTime
Sourcepub const fn new(
year: i16,
month: i8,
day: i8,
hour: i8,
minute: i8,
second: i8,
subsec_nanosecond: i32,
) -> Result<DateTime, RangeError>
pub const fn new( year: i16, month: i8, day: i8, hour: i8, minute: i8, second: i8, subsec_nanosecond: i32, ) -> Result<DateTime, RangeError>
Creates a new civil datetime from its constituent components.
If any of the values are out of their supported ranges, then an
error is returned. Additionally, if year, month and day do not
correspond to a valid Gregorian date, then an error is returned.
Sourcepub const fn from_parts(date: Date, time: Time) -> DateTime
pub const fn from_parts(date: Date, time: Time) -> DateTime
Sourcepub const fn checked_add_seconds(
&self,
seconds: i32,
) -> Result<DateTime, RangeError>
pub const fn checked_add_seconds( &self, seconds: i32, ) -> Result<DateTime, RangeError>
Adds the given number of seconds to this civil datetime.
This returns an error when the resulting datetime would exceed either
DateTime::MIN or DateTime::MAX.
Sourcepub const fn saturating_add_seconds(&self, seconds: i32) -> DateTime
pub const fn saturating_add_seconds(&self, seconds: i32) -> DateTime
Like DateTime::checked_add_seconds, but arithmetic saturates to
either DateTime::MIN (when seconds < 0) or DateTime::MAX
(when seconds > 0).
Sourcepub const fn to_timestamp(
&self,
offset: Offset,
) -> Result<Timestamp, RangeError>
pub const fn to_timestamp( &self, offset: Offset, ) -> Result<Timestamp, RangeError>
Converts this datetime, along with its offset from UTC, to a corresponding Unix timestamp.
Note that unlike the reverse operation, Timestamp::to_datetime,
this is fallible. This is by design. Namely, by making this routine
fallible at the boundaries, it permits the reverse operation to be
infallible. That is, all instants can be converted to a civil datetime
(appropriate for formatting), but not all civil datetimes combined with
all UTC offsets can be converted to an instant in time.
This errors when the timestamp returned would be outside the range
given by Timestamp::MIN and Timestamp::MAX.
Trait Implementations§
impl Copy for DateTime
impl Eq for DateTime
Source§impl From<DateTime> for DateTime
Creates a new bit packed datetime from jiff-core’s standard datetime type.
impl From<DateTime> for DateTime
Creates a new bit packed datetime from jiff-core’s standard datetime type.
Note that this completely ignores any fractional second component on the provided datetime.