DateTime

Struct DateTime 

Source
pub struct DateTime {
    pub year: i32,
    pub month: u8,
    pub day: u8,
    pub hour: u8,
    pub minute: u8,
    pub second: u8,
}
Expand description

A broken-down civil date and time, in UTC unless a caller has deliberately shifted it.

Fields§

§year: i32

Proleptic Gregorian year.

§month: u8

Month, 1–12.

§day: u8

Day of month, 1–31.

§hour: u8

Hour, 0–23.

§minute: u8

Minute, 0–59.

§second: u8

Second, 0–59. Leap seconds are not represented: receivers report UTC with the leap second smeared or repeated, and a second that cannot be encoded is worse than one that is merely repeated.

Implementations§

Source§

impl DateTime

Source

pub const EPOCH: Self

The Unix epoch itself, 1970-01-01T00:00:00Z.

Source

pub const fn is_valid(&self) -> bool

Whether every field is in range and the day exists in its month.

Note what this does not check: a year outside the range to_unix can encode is still a valid date, and is rejected there instead.

Source

pub const fn to_unix(&self) -> Option<u32>

Seconds since the Unix epoch, or None when the date is invalid or falls outside what PROP_TIME can carry.

A receiver reporting a date before 1970 or past 2106 is reporting a receiver fault, not a time, so refusing is the right answer: silently clamping would set a clock to a value the device would then defend.

Source

pub const fn from_unix(seconds: u32) -> Self

Break a Unix second count down into civil fields.

Total: every u32 names a real UTC instant, so unlike to_unix there is nothing to refuse.

Source

pub const fn shifted(&self, offset_minutes: i16) -> Option<Self>

This instant shifted by a time-zone offset in minutes east of UTC, for rendering a local time.

The result is a wall-clock reading, not an instant: it no longer converts back through to_unix to what it came from, which is exactly what makes it presentation. None when the shift leaves the representable range.

Trait Implementations§

Source§

impl Clone for DateTime

Source§

fn clone(&self) -> DateTime

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DateTime

Source§

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

Formats the value using the given formatter. 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§

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

Compares and returns the maximum of two values. Read more
1.21.0§

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

Compares and returns the minimum of two values. Read more
1.50.0§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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§

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

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

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§

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

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

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 Copy for DateTime

Source§

impl Eq for DateTime

Source§

impl StructuralPartialEq for DateTime

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.