pub struct CustomDateTime(NaiveDateTime);Expand description
CustomDateTime is a wrapper around NaiveDateTime that provides additional functionality.
Tuple Fields§
§0: NaiveDateTimeImplementations§
Source§impl CustomDateTime
CustomDateTime implementing certain useful methods.
impl CustomDateTime
CustomDateTime implementing certain useful methods.
Sourcepub fn inner(&self) -> NaiveDateTime
pub fn inner(&self) -> NaiveDateTime
Returns the inner NaiveDateTime.
Methods from Deref<Target = NaiveDateTime>§
pub const MIN: NaiveDateTime
pub const MAX: NaiveDateTime
pub const UNIX_EPOCH: NaiveDateTime
Sourcepub fn date(&self) -> NaiveDate
pub fn date(&self) -> NaiveDate
Retrieves a date component.
§Example
use chrono::NaiveDate;
let dt = NaiveDate::from_ymd_opt(2016, 7, 8).unwrap().and_hms_opt(9, 10, 11).unwrap();
assert_eq!(dt.date(), NaiveDate::from_ymd_opt(2016, 7, 8).unwrap());Sourcepub fn time(&self) -> NaiveTime
pub fn time(&self) -> NaiveTime
Retrieves a time component.
§Example
use chrono::{NaiveDate, NaiveTime};
let dt = NaiveDate::from_ymd_opt(2016, 7, 8).unwrap().and_hms_opt(9, 10, 11).unwrap();
assert_eq!(dt.time(), NaiveTime::from_hms_opt(9, 10, 11).unwrap());Sourcepub fn timestamp(&self) -> i64
👎Deprecated since 0.4.35: use .and_utc().timestamp() instead
pub fn timestamp(&self) -> i64
use .and_utc().timestamp() instead
Returns the number of non-leap seconds since the midnight on January 1, 1970.
Note that this does not account for the timezone! The true “UNIX timestamp” would count seconds since the midnight UTC on the epoch.
Sourcepub fn timestamp_millis(&self) -> i64
👎Deprecated since 0.4.35: use .and_utc().timestamp_millis() instead
pub fn timestamp_millis(&self) -> i64
use .and_utc().timestamp_millis() instead
Returns the number of non-leap milliseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true “UNIX timestamp” would count seconds since the midnight UTC on the epoch.
Sourcepub fn timestamp_micros(&self) -> i64
👎Deprecated since 0.4.35: use .and_utc().timestamp_micros() instead
pub fn timestamp_micros(&self) -> i64
use .and_utc().timestamp_micros() instead
Returns the number of non-leap microseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true “UNIX timestamp” would count seconds since the midnight UTC on the epoch.
Sourcepub fn timestamp_nanos(&self) -> i64
👎Deprecated since 0.4.31: use .and_utc().timestamp_nanos_opt() instead
pub fn timestamp_nanos(&self) -> i64
use .and_utc().timestamp_nanos_opt() instead
Returns the number of non-leap nanoseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true “UNIX timestamp” would count seconds since the midnight UTC on the epoch.
§Panics
An i64 with nanosecond precision can span a range of ~584 years. This function panics on
an out of range NaiveDateTime.
The dates that can be represented as nanoseconds are between 1677-09-21T00:12:43.145224192 and 2262-04-11T23:47:16.854775807.
Sourcepub fn timestamp_nanos_opt(&self) -> Option<i64>
👎Deprecated since 0.4.35: use .and_utc().timestamp_nanos_opt() instead
pub fn timestamp_nanos_opt(&self) -> Option<i64>
use .and_utc().timestamp_nanos_opt() instead
Returns the number of non-leap nanoseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true “UNIX timestamp” would count seconds since the midnight UTC on the epoch.
§Errors
An i64 with nanosecond precision can span a range of ~584 years. This function returns
None on an out of range NaiveDateTime.
The dates that can be represented as nanoseconds are between 1677-09-21T00:12:43.145224192 and 2262-04-11T23:47:16.854775807.
Sourcepub fn timestamp_subsec_millis(&self) -> u32
👎Deprecated since 0.4.35: use .and_utc().timestamp_subsec_millis() instead
pub fn timestamp_subsec_millis(&self) -> u32
use .and_utc().timestamp_subsec_millis() instead
Returns the number of milliseconds since the last whole non-leap second.
The return value ranges from 0 to 999, or for leap seconds, to 1,999.
Sourcepub fn timestamp_subsec_micros(&self) -> u32
👎Deprecated since 0.4.35: use .and_utc().timestamp_subsec_micros() instead
pub fn timestamp_subsec_micros(&self) -> u32
use .and_utc().timestamp_subsec_micros() instead
Returns the number of microseconds since the last whole non-leap second.
The return value ranges from 0 to 999,999, or for leap seconds, to 1,999,999.
Sourcepub fn timestamp_subsec_nanos(&self) -> u32
👎Deprecated since 0.4.36: use .and_utc().timestamp_subsec_nanos() instead
pub fn timestamp_subsec_nanos(&self) -> u32
use .and_utc().timestamp_subsec_nanos() instead
Returns the number of nanoseconds since the last whole non-leap second.
The return value ranges from 0 to 999,999,999, or for leap seconds, to 1,999,999,999.
Sourcepub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
Formats the combined date and time with the specified formatting items.
Otherwise it is the same as the ordinary format method.
The Iterator of items should be Cloneable,
since the resulting DelayedFormat value may be formatted multiple times.
§Example
use chrono::format::strftime::StrftimeItems;
use chrono::NaiveDate;
let fmt = StrftimeItems::new("%Y-%m-%d %H:%M:%S");
let dt = NaiveDate::from_ymd_opt(2015, 9, 5).unwrap().and_hms_opt(23, 56, 4).unwrap();
assert_eq!(dt.format_with_items(fmt.clone()).to_string(), "2015-09-05 23:56:04");
assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2015-09-05 23:56:04");The resulting DelayedFormat can be formatted directly via the Display trait.
assert_eq!(format!("{}", dt.format_with_items(fmt)), "2015-09-05 23:56:04");Sourcepub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
Formats the combined date and time with the specified format string.
See the format::strftime module
on the supported escape sequences.
This returns a DelayedFormat,
which gets converted to a string only when actual formatting happens.
You may use the to_string method to get a String,
or just feed it into print! and other formatting macros.
(In this way it avoids the redundant memory allocation.)
A wrong format string does not issue an error immediately.
Rather, converting or formatting the DelayedFormat fails.
You are recommended to immediately use DelayedFormat for this reason.
§Example
use chrono::NaiveDate;
let dt = NaiveDate::from_ymd_opt(2015, 9, 5).unwrap().and_hms_opt(23, 56, 4).unwrap();
assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2015-09-05 23:56:04");
assert_eq!(dt.format("around %l %p on %b %-d").to_string(), "around 11 PM on Sep 5");The resulting DelayedFormat can be formatted directly via the Display trait.
assert_eq!(format!("{}", dt.format("%Y-%m-%d %H:%M:%S")), "2015-09-05 23:56:04");
assert_eq!(format!("{}", dt.format("around %l %p on %b %-d")), "around 11 PM on Sep 5");Sourcepub fn and_local_timezone<Tz>(&self, tz: Tz) -> LocalResult<DateTime<Tz>>where
Tz: TimeZone,
pub fn and_local_timezone<Tz>(&self, tz: Tz) -> LocalResult<DateTime<Tz>>where
Tz: TimeZone,
Converts the NaiveDateTime into a timezone-aware DateTime<Tz> with the provided
time zone.
§Example
use chrono::{FixedOffset, NaiveDate};
let hour = 3600;
let tz = FixedOffset::east_opt(5 * hour).unwrap();
let dt = NaiveDate::from_ymd_opt(2015, 9, 5)
.unwrap()
.and_hms_opt(23, 56, 4)
.unwrap()
.and_local_timezone(tz)
.unwrap();
assert_eq!(dt.timezone(), tz);Trait Implementations§
Source§impl Add<TimeDelta> for CustomDateTime
Add implementation for CustomDateTime.
impl Add<TimeDelta> for CustomDateTime
Add implementation for CustomDateTime.
Source§impl AddAssign<TimeDelta> for CustomDateTime
AddAssign implementation for CustomDateTime.
impl AddAssign<TimeDelta> for CustomDateTime
AddAssign implementation for CustomDateTime.
Source§fn add_assign(&mut self, other: TimeDelta)
fn add_assign(&mut self, other: TimeDelta)
Adds a TimeDelta to the CustomDateTime.
Source§impl<'__expr> AsExpression<Datetime> for &'__expr CustomDateTime
impl<'__expr> AsExpression<Datetime> for &'__expr CustomDateTime
Source§type Expression = Bound<Datetime, &'__expr CustomDateTime>
type Expression = Bound<Datetime, &'__expr CustomDateTime>
Source§fn as_expression(self) -> <Self as AsExpression<Datetime>>::Expression
fn as_expression(self) -> <Self as AsExpression<Datetime>>::Expression
Source§impl AsExpression<Datetime> for CustomDateTime
impl AsExpression<Datetime> for CustomDateTime
Source§type Expression = Bound<Datetime, CustomDateTime>
type Expression = Bound<Datetime, CustomDateTime>
Source§fn as_expression(self) -> <Self as AsExpression<Datetime>>::Expression
fn as_expression(self) -> <Self as AsExpression<Datetime>>::Expression
Source§impl<'__expr> AsExpression<Nullable<Datetime>> for &'__expr CustomDateTime
impl<'__expr> AsExpression<Nullable<Datetime>> for &'__expr CustomDateTime
Source§type Expression = Bound<Nullable<Datetime>, &'__expr CustomDateTime>
type Expression = Bound<Nullable<Datetime>, &'__expr CustomDateTime>
Source§fn as_expression(self) -> <Self as AsExpression<Nullable<Datetime>>>::Expression
fn as_expression(self) -> <Self as AsExpression<Nullable<Datetime>>>::Expression
Source§impl AsExpression<Nullable<Datetime>> for CustomDateTime
impl AsExpression<Nullable<Datetime>> for CustomDateTime
Source§type Expression = Bound<Nullable<Datetime>, CustomDateTime>
type Expression = Bound<Nullable<Datetime>, CustomDateTime>
Source§fn as_expression(self) -> <Self as AsExpression<Nullable<Datetime>>>::Expression
fn as_expression(self) -> <Self as AsExpression<Nullable<Datetime>>>::Expression
Source§impl Clone for CustomDateTime
impl Clone for CustomDateTime
Source§fn clone(&self) -> CustomDateTime
fn clone(&self) -> CustomDateTime
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CustomDateTime
Source§impl Debug for CustomDateTime
impl Debug for CustomDateTime
Source§impl Deref for CustomDateTime
Deref implementation for CustomDateTime.
impl Deref for CustomDateTime
Deref implementation for CustomDateTime.
Source§impl<'de> Deserialize<'de> for CustomDateTime
Deserialize implementation for CustomDateTime.
impl<'de> Deserialize<'de> for CustomDateTime
Deserialize implementation for CustomDateTime.
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>,
Deserializes a JSON string into a CustomDateTime.
impl Eq for CustomDateTime
Source§impl From<NaiveDateTime> for CustomDateTime
From<NaiveDateTime> implementation for CustomDateTime.
impl From<NaiveDateTime> for CustomDateTime
From<NaiveDateTime> implementation for CustomDateTime.
Source§fn from(dt: NaiveDateTime) -> Self
fn from(dt: NaiveDateTime) -> Self
Converts a NaiveDateTime to a CustomDateTime.
Source§impl FromSql<Datetime, Mysql> for CustomDateTime
FromSql implementation for CustomDateTime.
impl FromSql<Datetime, Mysql> for CustomDateTime
FromSql implementation for CustomDateTime.
Source§impl Ord for CustomDateTime
impl Ord for CustomDateTime
Source§fn cmp(&self, other: &CustomDateTime) -> Ordering
fn cmp(&self, other: &CustomDateTime) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for CustomDateTime
impl PartialEq for CustomDateTime
Source§fn eq(&self, other: &CustomDateTime) -> bool
fn eq(&self, other: &CustomDateTime) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for CustomDateTime
impl PartialOrd for CustomDateTime
Source§impl<__DB, __ST> Queryable<__ST, __DB> for CustomDateTimewhere
__DB: Backend,
__ST: SingleValue,
Self: FromSql<__ST, __DB>,
impl<__DB, __ST> Queryable<__ST, __DB> for CustomDateTimewhere
__DB: Backend,
__ST: SingleValue,
Self: FromSql<__ST, __DB>,
Source§impl Serialize for CustomDateTime
Serialize implementation for CustomDateTime.
impl Serialize for CustomDateTime
Serialize implementation for CustomDateTime.
impl StructuralPartialEq for CustomDateTime
Source§impl<DB> ToSql<Datetime, DB> for CustomDateTimewhere
DB: Backend,
NaiveDateTime: ToSql<Datetime, DB>,
ToSql implementation for CustomDateTime.
impl<DB> ToSql<Datetime, DB> for CustomDateTimewhere
DB: Backend,
NaiveDateTime: ToSql<Datetime, DB>,
ToSql implementation for CustomDateTime.
Auto Trait Implementations§
impl Freeze for CustomDateTime
impl RefUnwindSafe for CustomDateTime
impl Send for CustomDateTime
impl Sync for CustomDateTime
impl Unpin for CustomDateTime
impl UnsafeUnpin for CustomDateTime
impl UnwindSafe for CustomDateTime
Blanket Implementations§
§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read more§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read more§fn aggregate_filter<P>(self, f: P) -> Self::Outputwhere
P: AsExpression<Bool>,
Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,
fn aggregate_filter<P>(self, f: P) -> Self::Outputwhere
P: AsExpression<Bool>,
Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,
§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
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<T> CloneAny for T
impl<T> CloneAny for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DebugAny for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§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.