Skip to main content

DateTime

Struct DateTime 

Source
pub struct DateTime { /* private fields */ }
Expand description

A civil time of a day on a particular Gregorian date.

Implementations§

Source§

impl DateTime

Source

pub const MIN: DateTime

The minimum allowed Gregorian date and clock time.

Source

pub const MAX: DateTime

The maximum allowed Gregorian date and clock time.

Source

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.

Source

pub const fn from_parts(date: Date, time: Time) -> DateTime

Creates a new DateTime from its Date and Time components.

Source

pub const fn date(&self) -> Date

Returns the Gregorian date component of this datetime.

Source

pub const fn time(&self) -> Time

Returns the civil time component of this datetime.

Source

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.

Source

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).

Source

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§

Source§

impl Clone for DateTime

Source§

fn clone(&self) -> DateTime

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DateTime

Source§

impl Debug for DateTime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DateTime

Source§

impl Format for DateTime

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

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.

Source§

fn from(dt: DateTime) -> DateTime

Converts to this type from the input type.
Source§

impl Hash for DateTime

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for DateTime

Source§

fn cmp(&self, other: &DateTime) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for DateTime

Source§

fn eq(&self, other: &DateTime) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for DateTime

Source§

fn partial_cmp(&self, other: &DateTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for DateTime

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.