pub struct ZonedDatetime { /* private fields */ }Expand description
A datetime with a fixed UTC offset.
Internally stores the instant as microseconds since the Unix epoch
(same as Timestamp) plus an offset in seconds from UTC. Two
ZonedDatetime values are equal when they refer to the same instant,
even if their offsets differ.
§Examples
use grafeo_common::types::ZonedDatetime;
let zdt = ZonedDatetime::parse("2024-06-15T10:30:00+05:30").unwrap();
assert_eq!(zdt.offset_seconds(), 19800);
assert_eq!(zdt.to_string(), "2024-06-15T10:30:00+05:30");Implementations§
Source§impl ZonedDatetime
impl ZonedDatetime
Sourcepub const fn from_timestamp_offset(ts: Timestamp, offset_seconds: i32) -> Self
pub const fn from_timestamp_offset(ts: Timestamp, offset_seconds: i32) -> Self
Creates a ZonedDatetime from a UTC timestamp and an offset in seconds.
Sourcepub fn from_date_time(date: Date, time: Time) -> Option<Self>
pub fn from_date_time(date: Date, time: Time) -> Option<Self>
Creates a ZonedDatetime from a date and a time with a required offset.
Returns None if the time has no offset.
Sourcepub const fn as_timestamp(&self) -> Timestamp
pub const fn as_timestamp(&self) -> Timestamp
Returns the underlying UTC timestamp.
Sourcepub const fn offset_seconds(&self) -> i32
pub const fn offset_seconds(&self) -> i32
Returns the UTC offset in seconds.
Sourcepub fn to_local_date(&self) -> Date
pub fn to_local_date(&self) -> Date
Returns the date in the local (offset-adjusted) timezone.
Sourcepub fn to_local_time(&self) -> Time
pub fn to_local_time(&self) -> Time
Returns the time-of-day in the local (offset-adjusted) timezone, carrying the offset.
Trait Implementations§
Source§impl Clone for ZonedDatetime
impl Clone for ZonedDatetime
Source§fn clone(&self) -> ZonedDatetime
fn clone(&self) -> ZonedDatetime
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ZonedDatetime
impl Debug for ZonedDatetime
Source§impl<'de> Deserialize<'de> for ZonedDatetime
impl<'de> Deserialize<'de> for ZonedDatetime
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 Display for ZonedDatetime
impl Display for ZonedDatetime
Source§impl From<ZonedDatetime> for Value
impl From<ZonedDatetime> for Value
Source§fn from(zdt: ZonedDatetime) -> Self
fn from(zdt: ZonedDatetime) -> Self
Converts to this type from the input type.
Source§impl Hash for ZonedDatetime
impl Hash for ZonedDatetime
Source§impl Ord for ZonedDatetime
impl Ord for ZonedDatetime
Source§impl PartialEq for ZonedDatetime
impl PartialEq for ZonedDatetime
Source§impl PartialOrd for ZonedDatetime
impl PartialOrd for ZonedDatetime
Source§impl Serialize for ZonedDatetime
impl Serialize for ZonedDatetime
impl Copy for ZonedDatetime
impl Eq for ZonedDatetime
Auto Trait Implementations§
impl Freeze for ZonedDatetime
impl RefUnwindSafe for ZonedDatetime
impl Send for ZonedDatetime
impl Sync for ZonedDatetime
impl Unpin for ZonedDatetime
impl UnsafeUnpin for ZonedDatetime
impl UnwindSafe for ZonedDatetime
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.