Skip to main content

DateTime

Struct DateTime 

Source
pub struct DateTime<TZ> { /* private fields */ }
Expand description

ISO-8601 representation with timezones.

Implementations§

Source§

impl<TZ> DateTime<TZ>
where TZ: TimeZone,

Source

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.

Source

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>

Source

pub const CE: Self

Instance that refers the common era (0001-01-01).

Source

pub const EPOCH: Self

Instance that refers the UNIX epoch (1970-01-01).

Source

pub const MAX: Self

Instance with the maximum allowed value of 32768-12-31 24:59:59.999_999_999

Source

pub const MIN: Self

Instance with the minimum allowed value of -32768-01-01 00:00:00.000_000_000

Source

pub fn from_timestamp_secs(second: i64) -> Result<Self>

Creates a new instance from a UNIX timestamp expressed in seconds.

Source

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,

Source

pub fn from_iso8601(bytes: &[u8]) -> Result<Self>

Creates a new instance based on the string representation of the ISO-8601 specification.

Source

pub const fn new(date: Date, time: Time, time_zone: TZ) -> Self

New instance from basic parameters

Source

pub const fn add(self, duration: Duration) -> Result<Self, CalendarError>

Computes self + duration, returning an error if an overflow occurred.

Source

pub const fn date(self) -> Date

See Date.

Source

pub fn iso8601(self) -> ArrayStringU8<38>

ISO-8601 string representation

Source

pub const fn sub(self, duration: Duration) -> Result<Self, CalendarError>

Computes self - duration, returning an error if an underflow occurred.

Source

pub const fn time(self) -> Time

See Time.

Source

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.

Source

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.

Source

pub fn to_utc(self) -> Result<DateTime<Utc>, CalendarError>

Returns a new instance with the internal values converted to UTC.

Source

pub const fn trunc_to_ms(self) -> Self

Returns a new instance with the number of nanoseconds truncated to milliseconds.

Source

pub const fn trunc_to_sec(self) -> Self

Returns a new instance with the number of nanoseconds totally erased.

Source

pub const fn trunc_to_us(self) -> Self

Returns a new instance with the number of nanoseconds truncated to microseconds.

Trait Implementations§

Source§

impl<TZ: Clone> Clone for DateTime<TZ>

Source§

fn clone(&self) -> DateTime<TZ>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<TZ> Debug for DateTime<TZ>
where TZ: TimeZone,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<E> Decode<'_, Mysql<E>> for DateTime<Utc>
where E: From<Error>,

Available on crate features mysql and database only.
Source§

fn decode(dw: &mut DecodeWrapper<'_, '_>) -> Result<Self, E>

Performs the conversion.
Source§

impl<E> Decode<'_, Postgres<E>> for DateTime<Utc>
where E: From<Error>,

Available on crate features postgres and database only.
Source§

fn decode(dw: &mut DecodeWrapper<'_, '_>) -> Result<Self, E>

Performs the conversion.
Source§

impl Default for DateTime<Utc>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, TZ> Deserialize<'de> for DateTime<TZ>
where TZ: TimeZone,

Available on crate feature serde only.
Source§

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<TZ> Display for DateTime<TZ>
where TZ: TimeZone,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<E> Encode<Mysql<E>> for DateTime<Utc>
where E: From<Error>,

Available on crate features mysql and database only.
Source§

fn encode(&self, ew: &mut EncodeWrapper<'_>) -> Result<(), E>

Performs the conversion.
Source§

fn is_null(&self) -> bool

If this instance can be desired nullable.
Source§

impl<E> Encode<Postgres<E>> for DateTime<Utc>
where E: From<Error>,

Available on crate features postgres and database only.
Source§

fn encode(&self, ew: &mut EncodeWrapper<'_, '_>) -> Result<(), E>

Performs the conversion.
Source§

fn is_null(&self) -> bool

If this instance can be desired nullable.
Source§

impl<TZ: Hash> Hash for DateTime<TZ>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<TZ: Ord> Ord for DateTime<TZ>

Source§

fn cmp(&self, other: &DateTime<TZ>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

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

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

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

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

Restrict a value to a certain interval. Read more
Source§

impl<TZ: PartialEq> PartialEq for DateTime<TZ>

Source§

fn eq(&self, other: &DateTime<TZ>) -> bool

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

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<TZ: PartialOrd> PartialOrd for DateTime<TZ>

Source§

fn partial_cmp(&self, other: &DateTime<TZ>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

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

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 · Source§

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

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

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<TZ> Serialize for DateTime<TZ>
where TZ: TimeZone,

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<E> Typed<Mysql<E>> for DateTime<Utc>
where E: From<Error>,

Available on crate features mysql and database only.
Source§

fn runtime_ty(&self) -> Option<TyParams>

Type that is only known at runtime.
Source§

fn static_ty() -> Option<TyParams>

Type that is known at compile time.
Source§

impl<E> Typed<Postgres<E>> for DateTime<Utc>
where E: From<Error>,

Available on crate features postgres and database only.
Source§

fn runtime_ty(&self) -> Option<Ty>

Type that is only known at runtime.
Source§

fn static_ty() -> Option<Ty>

Type that is known at compile time.
Source§

impl<TZ: Copy> Copy for DateTime<TZ>

Source§

impl<TZ: Eq> Eq for DateTime<TZ>

Source§

impl<TZ> StructuralPartialEq for DateTime<TZ>

Auto Trait Implementations§

§

impl<TZ> Freeze for DateTime<TZ>
where TZ: Freeze,

§

impl<TZ> RefUnwindSafe for DateTime<TZ>
where TZ: RefUnwindSafe,

§

impl<TZ> Send for DateTime<TZ>
where TZ: Send,

§

impl<TZ> Sync for DateTime<TZ>
where TZ: Sync,

§

impl<TZ> Unpin for DateTime<TZ>
where TZ: Unpin,

§

impl<TZ> UnwindSafe for DateTime<TZ>
where TZ: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<D, T> TypedEncode<D> for T
where D: Database, T: Encode<D> + Typed<D>,