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: i32Proleptic Gregorian year.
month: u8Month, 1–12.
day: u8Day of month, 1–31.
hour: u8Hour, 0–23.
minute: u8Minute, 0–59.
second: u8Second, 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
impl DateTime
Sourcepub const fn is_valid(&self) -> bool
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.
Sourcepub const fn to_unix(&self) -> Option<u32>
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.
Sourcepub const fn from_unix(seconds: u32) -> Self
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.
Sourcepub const fn shifted(&self, offset_minutes: i16) -> Option<Self>
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 Ord for DateTime
impl Ord for DateTime
Source§impl PartialOrd for DateTime
impl PartialOrd for DateTime
impl Copy for DateTime
impl Eq for DateTime
impl StructuralPartialEq for DateTime
Auto Trait Implementations§
impl Freeze for DateTime
impl RefUnwindSafe for DateTime
impl Send for DateTime
impl Sync for DateTime
impl Unpin for DateTime
impl UnwindSafe for DateTime
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)