pub struct DateTime<TZ> { /* private fields */ }Expand description
ISO-8601 representation with timezones.
Implementations§
Source§impl<TZ> DateTime<TZ>where
TZ: TimeZone,
impl<TZ> DateTime<TZ>where
TZ: TimeZone,
Sourcepub fn parse(
bytes: &[u8],
tokens: impl IntoIterator<Item = CalendarToken>,
) -> Result<Self>
pub fn parse( bytes: &[u8], tokens: impl IntoIterator<Item = CalendarToken>, ) -> Result<Self>
Parses a sequence of bytes according to the specified tokens.
See CalendarToken for more information.
Sourcepub fn to_string<const N: usize>(
&self,
tokens: impl IntoIterator<Item = CalendarToken>,
) -> Result<ArrayStringU8<N>>
pub fn to_string<const N: usize>( &self, tokens: impl IntoIterator<Item = CalendarToken>, ) -> Result<ArrayStringU8<N>>
Creates a string representation based on the given tokens.
A string of 32 bytes is usually more than enough for most representations.
See CalendarToken for more information.
Source§impl DateTime<Utc>
impl DateTime<Utc>
Sourcepub const MAX: Self
pub const MAX: Self
Instance with the maximum allowed value of 32768-12-31 24:59:59.999_999_999
Sourcepub const MIN: Self
pub const MIN: Self
Instance with the minimum allowed value of -32768-01-01 00:00:00.000_000_000
Sourcepub fn from_timestamp_secs(second: i64) -> Result<Self>
pub fn from_timestamp_secs(second: i64) -> Result<Self>
Creates a new instance from a UNIX timestamp expressed in seconds.
Sourcepub fn from_timestamp_secs_and_ns(
seconds: i64,
nanoseconds: Nanosecond,
) -> Result<Self>
pub fn from_timestamp_secs_and_ns( seconds: i64, nanoseconds: Nanosecond, ) -> Result<Self>
Creates a new instance from a UNIX timestamp expressed in seconds along side the number of nanoseconds.
Source§impl<TZ> DateTime<TZ>where
TZ: TimeZone,
impl<TZ> DateTime<TZ>where
TZ: TimeZone,
Sourcepub fn from_iso8601(bytes: &[u8]) -> Result<Self>
pub fn from_iso8601(bytes: &[u8]) -> Result<Self>
Creates a new instance based on the string representation of the ISO-8601 specification.
Sourcepub const fn new(date: Date, time: Time, time_zone: TZ) -> Self
pub const fn new(date: Date, time: Time, time_zone: TZ) -> Self
New instance from basic parameters
Sourcepub const fn add(self, duration: Duration) -> Result<Self, CalendarError>
pub const fn add(self, duration: Duration) -> Result<Self, CalendarError>
Computes self + duration, returning an error if an overflow occurred.
Sourcepub fn iso8601(self) -> ArrayStringU8<38>
pub fn iso8601(self) -> ArrayStringU8<38>
ISO-8601 string representation
Sourcepub const fn sub(self, duration: Duration) -> Result<Self, CalendarError>
pub const fn sub(self, duration: Duration) -> Result<Self, CalendarError>
Computes self - duration, returning an error if an underflow occurred.
Sourcepub const fn timestamp_secs_and_ns(self) -> (i64, Nanosecond)
pub const fn timestamp_secs_and_ns(self) -> (i64, Nanosecond)
UNIX timestamp in seconds as well as the number of nanoseconds.
It is worth noting that it is much cheaper to get the timestamp using Instant.
Sourcepub fn to_tz<NTZ>(self, tz: NTZ) -> Result<DateTime<NTZ>, CalendarError>where
NTZ: TimeZone,
pub fn to_tz<NTZ>(self, tz: NTZ) -> Result<DateTime<NTZ>, CalendarError>where
NTZ: TimeZone,
Returns a new instance with the internal values converted to the provided timezone.
Sourcepub fn to_utc(self) -> Result<DateTime<Utc>, CalendarError>
pub fn to_utc(self) -> Result<DateTime<Utc>, CalendarError>
Returns a new instance with the internal values converted to UTC.
Sourcepub const fn trunc_to_ms(self) -> Self
pub const fn trunc_to_ms(self) -> Self
Returns a new instance with the number of nanoseconds truncated to milliseconds.
Sourcepub const fn trunc_to_sec(self) -> Self
pub const fn trunc_to_sec(self) -> Self
Returns a new instance with the number of nanoseconds totally erased.
Sourcepub const fn trunc_to_us(self) -> Self
pub const fn trunc_to_us(self) -> Self
Returns a new instance with the number of nanoseconds truncated to microseconds.
Trait Implementations§
Source§impl<E> Decode<'_, Mysql<E>> for DateTime<Utc>
Available on crate features mysql and database only.
impl<E> Decode<'_, Mysql<E>> for DateTime<Utc>
mysql and database only.Source§fn decode(dw: &mut DecodeWrapper<'_, '_>) -> Result<Self, E>
fn decode(dw: &mut DecodeWrapper<'_, '_>) -> Result<Self, E>
Source§impl<E> Decode<'_, Postgres<E>> for DateTime<Utc>
Available on crate features postgres and database only.
impl<E> Decode<'_, Postgres<E>> for DateTime<Utc>
postgres and database only.Source§fn decode(dw: &mut DecodeWrapper<'_, '_>) -> Result<Self, E>
fn decode(dw: &mut DecodeWrapper<'_, '_>) -> Result<Self, E>
Source§impl<'de, TZ> Deserialize<'de> for DateTime<TZ>where
TZ: TimeZone,
Available on crate feature serde only.
impl<'de, TZ> Deserialize<'de> for DateTime<TZ>where
TZ: TimeZone,
serde only.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>,
Source§impl<E> Encode<Mysql<E>> for DateTime<Utc>
Available on crate features mysql and database only.
impl<E> Encode<Mysql<E>> for DateTime<Utc>
mysql and database only.Source§impl<E> Encode<Postgres<E>> for DateTime<Utc>
Available on crate features postgres and database only.
impl<E> Encode<Postgres<E>> for DateTime<Utc>
postgres and database only.Source§impl<TZ: Ord> Ord for DateTime<TZ>
impl<TZ: Ord> Ord for DateTime<TZ>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<TZ: PartialOrd> PartialOrd for DateTime<TZ>
impl<TZ: PartialOrd> PartialOrd for DateTime<TZ>
Source§impl<E> Typed<Mysql<E>> for DateTime<Utc>
Available on crate features mysql and database only.
impl<E> Typed<Mysql<E>> for DateTime<Utc>
mysql and database only.Source§impl<E> Typed<Postgres<E>> for DateTime<Utc>
Available on crate features postgres and database only.
impl<E> Typed<Postgres<E>> for DateTime<Utc>
postgres and database only.