DateTime

Struct DateTime 

Source
pub struct DateTime(/* private fields */);
Expand description

A wrapper type for chrono::DateTime<Local>.

Implementations§

Source§

impl DateTime

Source

pub fn now() -> Self

Returns a new instance which corresponds to the current date and time.

Source

pub fn current_timestamp() -> i64

Returns the number of non-leap seconds since the midnight UTC on January 1, 1970.

Source

pub fn current_timestamp_millis() -> i64

Returns the number of non-leap milliseconds since the midnight UTC on January 1, 1970.

Source

pub fn current_timestamp_micros() -> i64

Returns the number of non-leap microseconds since the midnight UTC on January 1, 1970.

Source

pub fn current_timestamp_nanos() -> i64

Returns the number of non-leap nanoseconds since the midnight UTC on January 1, 1970.

Source

pub fn from_timestamp(secs: i64) -> Self

Returns a new instance corresponding to a UTC date and time, from the number of non-leap seconds since the midnight UTC on January 1, 1970.

Source

pub fn from_timestamp_millis(millis: i64) -> Self

Returns a new instance corresponding to a UTC date and time, from the number of non-leap milliseconds since the midnight UTC on January 1, 1970.

Source

pub fn from_timestamp_micros(micros: i64) -> Self

Returns a new instance corresponding to a UTC date and time, from the number of non-leap microseconds since the midnight UTC on January 1, 1970.

Source

pub fn from_timestamp_nanos(nanos: i64) -> Self

Returns a new instance corresponding to a UTC date and time, from the number of non-leap nanoseconds since the midnight UTC on January 1, 1970.

Source

pub fn from_uuid_timestamp(ts: Timestamp) -> Self

Returns a new instance corresponding to a UTC date and time from a UUID timestamp.

Source

pub fn timestamp(&self) -> i64

Returns the number of non-leap seconds since the midnight UTC on January 1, 1970.

Source

pub fn timestamp_millis(&self) -> i64

Returns the number of non-leap milliseconds since the midnight UTC on January 1, 1970.

Source

pub fn timestamp_micros(&self) -> i64

Returns the number of non-leap microseconds since the midnight UTC on January 1, 1970.

Source

pub fn timestamp_nanos(&self) -> i64

Returns the number of non-leap nanoseconds since the midnight UTC on January 1, 1970.

Source

pub fn uuid_timestamp(&self) -> Timestamp

Returns a timestamp that can be encoded into a UUID.

Source

pub fn timezone_offset(&self) -> i32

Returns the difference in seconds between self and the same date-time as evaluated in the UTC time zone.

Source

pub fn parse_utc_str(s: &str) -> Result<Self, ParseError>

Parses an RFC 2822 date and time.

Source

pub fn parse_iso_str(s: &str) -> Result<Self, ParseError>

Parses an RFC 3339 and ISO 8601 date and time.

Source

pub fn parse_from_str(s: &str, fmt: &str) -> Result<Self, ParseError>

Parses a string with the specified format string. See format::strftime for the supported escape sequences.

Source

pub fn to_utc_timestamp(&self) -> String

Returns a UTC timestamp string.

Source

pub fn to_utc_string(&self) -> String

Returns an RFC 2822 date and time string.

Source

pub fn to_iso_string(&self) -> String

Return an RFC 3339 and ISO 8601 date and time string with subseconds formatted as SecondsFormat::Millis.

Source

pub fn to_local_string(&self) -> String

Returns a date-time string with the Local time zone.

Source

pub fn format(&self, fmt: &str) -> String

Formats the combined date and time with the specified format string. See format::strftime for the supported escape sequences.

Source

pub fn format_date(&self) -> String

Returns a date-only string in the format %Y-%m-%d.

Source

pub fn format_time(&self) -> String

Returns a time-only string in the format %H:%M:%S.

Source

pub fn format_local(&self) -> String

Returns a date-time string in the format %Y-%m-%d %H:%M:%S with the Local time zone.

Source

pub fn format_utc(&self) -> String

Returns a date-time string in the format %Y-%m-%d %H:%M:%S with the Utc time zone.

Source

pub fn duration_since(&self, earlier: DateTime) -> Duration

Returns the amount of time elapsed from another datetime to this one, or zero duration if that datetime is later than this one.

Source

pub fn span_between(&self, other: DateTime) -> Duration

Returns the duration of time between self and other.

Source

pub fn span_between_now(&self) -> Duration

Returns the duration of time between self and DateTime::now().

Source

pub fn span_before_now(&self) -> Option<Duration>

Returns the duration of time from self to DateTime::now().

Source

pub fn span_after_now(&self) -> Option<Duration>

Returns the duration of time from DateTime::now() to self.

Source

pub fn date(&self) -> Date

Retrieves the date component.

Source

pub fn time(&self) -> Time

Retrieves the time component.

Source

pub fn year(&self) -> i32

Returns the year number in the calendar date.

Source

pub fn quarter(&self) -> u32

Returns the quarter number starting from 1.

The return value ranges from 1 to 4.

Source

pub fn month(&self) -> u32

Returns the month number starting from 1.

The return value ranges from 1 to 12.

Source

pub fn day(&self) -> u32

Returns the day of month starting from 1.

The return value ranges from 1 to 31. (The last day of month differs by months.)

Source

pub fn hour(&self) -> u32

Returns the hour number from 0 to 23.

Source

pub fn minute(&self) -> u32

Returns the minute number from 0 to 59.

Source

pub fn second(&self) -> u32

Returns the second number from 0 to 59.

Source

pub fn millisecond(&self) -> u32

Returns the millisecond number from 0 to 999.

Source

pub fn microsecond(&self) -> u32

Returns the microsecond number from 0 to 999.

Source

pub fn nanosecond(&self) -> u32

Returns the nanosecond number from 0 to 999.

Source

pub fn week(&self) -> u32

Returns the ISO week number starting from 1.

The return value ranges from 1 to 53. (The last week of year differs by years.)

Source

pub fn day_of_year(&self) -> u32

Returns the day of year starting from 1.

The return value ranges from 1 to 366. (The last day of year differs by years.)

Source

pub fn day_of_week(&self) -> u8

Returns the day of week starting from 0 (Sunday) to 6 (Saturday).

Source

pub fn iso_day_of_week(&self) -> u8

Returns the ISO day of week starting from 1 (Monday) to 7 (Sunday).

Source

pub fn is_leap_year(&self) -> bool

Returns true if the current year is a leap year.

Source

pub fn is_weekend(&self) -> bool

Returns true if the current day is weekend.

Source

pub fn days_in_current_year(&self) -> u32

Returns the number of days in the current year.

Source

pub fn days_in_current_month(&self) -> u32

Returns the number of days in the current month.

Source

pub fn start_of_current_year(&self) -> Self

Returns the start of the current year.

Source

pub fn end_of_current_year(&self) -> Self

Returns the end of the current year.

Source

pub fn start_of_current_quarter(&self) -> Self

Returns the start of the current quarter.

Source

pub fn end_of_current_quarter(&self) -> Self

Returns the end of the current quarter.

Source

pub fn start_of_current_month(&self) -> Self

Returns the start of the current month.

Source

pub fn end_of_current_month(&self) -> Self

Returns the end of the current month.

Source

pub fn start_of_current_day(&self) -> Self

Returns the start of the current day.

Source

pub fn end_of_current_day(&self) -> Self

Returns the end of the current day.

Source

pub fn start_of_year(year: i32) -> Self

Returns the start of the year.

Source

pub fn end_of_year(year: i32) -> Self

Returns the end of the year.

Source

pub fn start_of_month(year: i32, month: u32) -> Self

Returns the start of the month.

Source

pub fn end_of_month(year: i32, month: u32) -> Self

Returns the end of the month.

Source

pub fn start_of_day(year: i32, month: u32, day: u32) -> Self

Returns the start of the day.

Source

pub fn end_of_day(year: i32, month: u32, day: u32) -> Self

Returns the end of the month.

Source

pub fn checked_add_months(self, months: u32) -> Option<Self>

Adds a duration in months to the date part of the DateTime. Returns None if the resulting date would be out of range.

Source

pub fn checked_sub_months(self, months: u32) -> Option<Self>

Subtracts a duration in months from the date part of the DateTime. Returns None if the resulting date would be out of range.

Source

pub fn checked_add_days(self, days: u32) -> Option<Self>

Adds a duration in days to the date part of the DateTime. Returns None if the resulting date would be out of range.

Source

pub fn checked_sub_days(self, days: u32) -> Option<Self>

Subtracts a duration in days from the date part of the DateTime. Returns None if the resulting date would be out of range.

Trait Implementations§

Source§

impl Add<Duration> for DateTime

Source§

type Output = DateTime

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Duration) -> Self

Performs the + operation. Read more
Source§

impl AddAssign<Duration> for DateTime

Source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
Source§

impl Clone for DateTime

Source§

fn clone(&self) -> DateTime

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 Debug for DateTime

Source§

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

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

impl<'r, DB> Decode<'r, DB> for DateTime
where DB: Database, DateTime<Local>: Decode<'r, DB>,

Available on crate feature sqlx only.
Source§

fn decode(value: <DB as Database>::ValueRef<'r>) -> Result<Self, BoxError>

Decode a new value of this type using a raw value from the database.
Source§

impl Default for DateTime

Source§

fn default() -> Self

Returns an instance which corresponds to the current date and time.

Source§

impl<'de> Deserialize<'de> for DateTime

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 Display for DateTime

Source§

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

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

impl From<Date> for DateTime

Source§

fn from(d: Date) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime<Local>> for DateTime

Source§

fn from(dt: DateTime<Local>) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime> for DateTime<Local>

Source§

fn from(dt: DateTime) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<DateTime> for FluentValue<'a>

Available on crate feature i18n only.
Source§

fn from(dt: DateTime) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime> for AvroValue

Source§

fn from(dt: DateTime) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime> for JsonValue

Source§

fn from(dt: DateTime) -> Self

Converts to this type from the input type.
Source§

impl FromStr for DateTime

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Ord for DateTime

Source§

fn cmp(&self, other: &DateTime) -> 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 PartialEq for DateTime

Source§

fn eq(&self, other: &DateTime) -> 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 PartialOrd for DateTime

Source§

fn partial_cmp(&self, other: &DateTime) -> 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 Serialize for DateTime

Source§

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

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

impl Sub<Duration> for DateTime

Source§

type Output = DateTime

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Duration) -> Self

Performs the - operation. Read more
Source§

impl SubAssign<Duration> for DateTime

Source§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more
Source§

impl<DB> Type<DB> for DateTime
where DB: Database, DateTime<Local>: Type<DB>,

Available on crate feature sqlx only.
Source§

fn type_info() -> <DB as Database>::TypeInfo

Returns the canonical SQL type for this Rust type. Read more
Source§

fn compatible(ty: &<DB as Database>::TypeInfo) -> bool

Determines if this Rust type is compatible with the given SQL type. Read more
Source§

impl Copy for DateTime

Source§

impl Eq for DateTime

Source§

impl StructuralPartialEq for DateTime

Auto Trait Implementations§

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> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

fn as_any(&self) -> &(dyn Any + 'static)

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> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

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

Source§

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

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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<T> ErasedDestructor for T
where T: 'static,