pub struct DateTime(/* private fields */);
Expand description
A wrapper type for chrono::DateTime<Local>
.
Implementations§
source§impl DateTime
impl DateTime
sourcepub fn current_timestamp() -> i64
pub fn current_timestamp() -> i64
Returns the number of non-leap seconds since the midnight UTC on January 1, 1970.
sourcepub fn current_timestamp_millis() -> i64
pub fn current_timestamp_millis() -> i64
Returns the number of non-leap milliseconds since the midnight UTC on January 1, 1970.
sourcepub fn current_timestamp_micros() -> i64
pub fn current_timestamp_micros() -> i64
Returns the number of non-leap microseconds since the midnight UTC on January 1, 1970.
sourcepub fn from_timestamp(secs: i64) -> Self
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.
sourcepub fn from_timestamp_millis(millis: i64) -> Self
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.
sourcepub fn from_timestamp_micros(micros: i64) -> Self
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.
sourcepub fn timestamp(&self) -> i64
pub fn timestamp(&self) -> i64
Returns the number of non-leap seconds since the midnight UTC on January 1, 1970.
sourcepub fn timestamp_millis(&self) -> i64
pub fn timestamp_millis(&self) -> i64
Returns the number of non-leap milliseconds since the midnight UTC on January 1, 1970.
sourcepub fn timestamp_micros(&self) -> i64
pub fn timestamp_micros(&self) -> i64
Returns the number of non-leap microseconds since the midnight UTC on January 1, 1970.
sourcepub fn timezone_offset(&self) -> i32
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.
sourcepub fn parse_utc_str(s: &str) -> Result<Self, ParseError>
pub fn parse_utc_str(s: &str) -> Result<Self, ParseError>
Parses an RFC 2822 date and time.
sourcepub fn parse_iso_str(s: &str) -> Result<Self, ParseError>
pub fn parse_iso_str(s: &str) -> Result<Self, ParseError>
Parses an RFC 3339 and ISO 8601 date and time.
sourcepub fn parse_from_str(s: &str, fmt: &str) -> Result<Self, ParseError>
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.
sourcepub fn to_utc_timestamp(&self) -> String
pub fn to_utc_timestamp(&self) -> String
Returns a UTC timestamp string.
sourcepub fn to_utc_string(&self) -> String
pub fn to_utc_string(&self) -> String
Returns an RFC 2822 date and time string.
sourcepub fn to_iso_string(&self) -> String
pub fn to_iso_string(&self) -> String
Return an RFC 3339 and ISO 8601 date and time string with subseconds
formatted as SecondsFormat::Millis
.
sourcepub fn format(&self, fmt: &str) -> String
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.
sourcepub fn format_date(&self) -> String
pub fn format_date(&self) -> String
Returns a date-only string in the format %Y-%m-%d
.
sourcepub fn format_time(&self) -> String
pub fn format_time(&self) -> String
Returns a time-only string in the format %H:%M:%S
.
sourcepub fn format_local(&self) -> String
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.
sourcepub fn format_utc(&self) -> String
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.
sourcepub fn duration_since(&self, earlier: DateTime) -> Duration
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.
sourcepub fn span_between(&self, other: DateTime) -> Duration
pub fn span_between(&self, other: DateTime) -> Duration
Returns the duration of time between self
and other
.
sourcepub fn span_between_now(&self) -> Duration
pub fn span_between_now(&self) -> Duration
Returns the duration of time between self
and DateTime::now()
.
sourcepub fn span_before_now(&self) -> Option<Duration>
pub fn span_before_now(&self) -> Option<Duration>
Returns the duration of time from self
to DateTime::now()
.
sourcepub fn span_after_now(&self) -> Option<Duration>
pub fn span_after_now(&self) -> Option<Duration>
Returns the duration of time from DateTime::now()
to self
.
sourcepub fn month(&self) -> u32
pub fn month(&self) -> u32
Returns the month number starting from 1.
The return value ranges from 1 to 12.
sourcepub fn day(&self) -> u32
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.)
sourcepub fn millisecond(&self) -> u32
pub fn millisecond(&self) -> u32
Returns the millisecond number from 0 to 999.
sourcepub fn microsecond(&self) -> u32
pub fn microsecond(&self) -> u32
Returns the microsecond number from 0 to 999.
sourcepub fn nanosecond(&self) -> u32
pub fn nanosecond(&self) -> u32
Returns the nanosecond number from 0 to 999.
sourcepub fn week(&self) -> u32
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.)
sourcepub fn day_of_year(&self) -> u32
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.)
sourcepub fn day_of_week(&self) -> u8
pub fn day_of_week(&self) -> u8
Returns the day of week starting from 0 (Sunday) to 6 (Saturday).
sourcepub fn iso_day_of_week(&self) -> u8
pub fn iso_day_of_week(&self) -> u8
Returns the ISO day of week starting from 1 (Monday) to 7 (Sunday).
sourcepub fn is_leap_year(&self) -> bool
pub fn is_leap_year(&self) -> bool
Returns true
if the current year is a leap year.
sourcepub fn is_weekend(&self) -> bool
pub fn is_weekend(&self) -> bool
Returns true
if the current day is weekend.
sourcepub fn days_in_current_year(&self) -> u32
pub fn days_in_current_year(&self) -> u32
Returns the number of days in the current year.
sourcepub fn days_in_current_month(&self) -> u32
pub fn days_in_current_month(&self) -> u32
Returns the number of days in the current month.
sourcepub fn start_of_current_year(&self) -> Self
pub fn start_of_current_year(&self) -> Self
Returns the start of the current year.
sourcepub fn end_of_current_year(&self) -> Self
pub fn end_of_current_year(&self) -> Self
Returns the end of the current year.
sourcepub fn start_of_current_month(&self) -> Self
pub fn start_of_current_month(&self) -> Self
Returns the start of the current month.
sourcepub fn end_of_current_month(&self) -> Self
pub fn end_of_current_month(&self) -> Self
Returns the end of the current month.
sourcepub fn start_of_current_day(&self) -> Self
pub fn start_of_current_day(&self) -> Self
Returns the start of the current day.
sourcepub fn end_of_current_day(&self) -> Self
pub fn end_of_current_day(&self) -> Self
Returns the end of the current day.
sourcepub fn start_of_year(year: i32) -> Self
pub fn start_of_year(year: i32) -> Self
Returns the start of the year.
sourcepub fn end_of_year(year: i32) -> Self
pub fn end_of_year(year: i32) -> Self
Returns the end of the year.
sourcepub fn start_of_month(year: i32, month: u32) -> Self
pub fn start_of_month(year: i32, month: u32) -> Self
Returns the start of the month.
sourcepub fn end_of_month(year: i32, month: u32) -> Self
pub fn end_of_month(year: i32, month: u32) -> Self
Returns the end of the month.
sourcepub fn start_of_day(year: i32, month: u32, day: u32) -> Self
pub fn start_of_day(year: i32, month: u32, day: u32) -> Self
Returns the start of the day.
sourcepub fn end_of_day(year: i32, month: u32, day: u32) -> Self
pub fn end_of_day(year: i32, month: u32, day: u32) -> Self
Returns the end of the month.
sourcepub fn checked_add_months(self, months: u32) -> Option<Self>
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.
sourcepub fn checked_sub_months(self, months: u32) -> Option<Self>
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.
sourcepub fn checked_add_days(self, days: u32) -> Option<Self>
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.
sourcepub fn checked_sub_days(self, days: u32) -> Option<Self>
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 AddAssign<Duration> for DateTime
impl AddAssign<Duration> for DateTime
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moresource§impl<'de> Deserialize<'de> for DateTime
impl<'de> Deserialize<'de> for DateTime
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 Ord for DateTime
impl Ord for DateTime
source§impl PartialEq for DateTime
impl PartialEq for DateTime
source§impl PartialOrd for DateTime
impl PartialOrd for DateTime
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign<Duration> for DateTime
impl SubAssign<Duration> for DateTime
source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moreimpl Copy for DateTime
impl Eq for DateTime
impl StructuralEq for DateTime
impl StructuralPartialEq for DateTime
Auto Trait Implementations§
impl RefUnwindSafe for DateTime
impl Send for DateTime
impl Sync for DateTime
impl Unpin for DateTime
impl UnwindSafe for DateTime
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> Conv for T
impl<T> Conv for T
§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T, U, I> LiftInto<U, I> for Twhere
U: LiftFrom<T, I>,
impl<T, U, I> LiftInto<U, I> for Twhere
U: LiftFrom<T, I>,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<Source> Sculptor<HNil, HNil> for Source
impl<Source> Sculptor<HNil, HNil> for Source
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.