pub struct Time { /* private fields */ }Expand description
A time of day with optional UTC offset.
Stored as nanoseconds since midnight plus an optional UTC offset in seconds. Without an offset, this is a “local time.”
§Examples
use grafeo_common::types::Time;
let t = Time::from_hms(14, 30, 0).unwrap();
assert_eq!(t.hour(), 14);
assert_eq!(t.minute(), 30);
assert_eq!(t.to_string(), "14:30:00");
let tz = t.with_offset(3600); // +01:00
assert_eq!(tz.to_string(), "14:30:00+01:00");Implementations§
Source§impl Time
impl Time
Sourcepub fn from_hms(hour: u32, min: u32, sec: u32) -> Option<Self>
pub fn from_hms(hour: u32, min: u32, sec: u32) -> Option<Self>
Creates a time from hours (0-23), minutes (0-59), and seconds (0-59).
Sourcepub fn from_hms_nano(hour: u32, min: u32, sec: u32, nano: u32) -> Option<Self>
pub fn from_hms_nano(hour: u32, min: u32, sec: u32, nano: u32) -> Option<Self>
Creates a time from hours, minutes, seconds, and nanoseconds.
Sourcepub fn from_nanos(nanos: u64) -> Option<Self>
pub fn from_nanos(nanos: u64) -> Option<Self>
Creates a time from nanoseconds since midnight.
Sourcepub fn with_offset(self, offset_secs: i32) -> Self
pub fn with_offset(self, offset_secs: i32) -> Self
Returns a new Time with the given UTC offset in seconds.
Sourcepub fn nanosecond(&self) -> u32
pub fn nanosecond(&self) -> u32
Returns the nanosecond component (0-999_999_999).
Sourcepub fn offset_seconds(&self) -> Option<i32>
pub fn offset_seconds(&self) -> Option<i32>
Returns the UTC offset in seconds, if present.
Sourcepub fn parse(s: &str) -> Option<Self>
pub fn parse(s: &str) -> Option<Self>
Parses a time from ISO 8601 format HH:MM:SS[.nnn][+HH:MM|Z].
Sourcepub fn add_duration(self, dur: &Duration) -> Self
pub fn add_duration(self, dur: &Duration) -> Self
Adds a duration’s time component to this time.
Only the nanosecond component of the duration is used (months and days are not meaningful for time-of-day). The result wraps around at midnight.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Time
impl<'de> Deserialize<'de> for Time
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Time
impl Ord for Time
Source§impl PartialOrd for Time
impl PartialOrd for Time
impl Copy for Time
impl Eq for Time
impl StructuralPartialEq for Time
Auto Trait Implementations§
impl Freeze for Time
impl RefUnwindSafe for Time
impl Send for Time
impl Sync for Time
impl Unpin for Time
impl UnsafeUnpin for Time
impl UnwindSafe for Time
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.