pub struct Date<Tz>where
Tz: TimeZone,{ /* private fields */ }NaiveDate or DateTime<Tz> insteadExpand description
ISO 8601 calendar date with time zone.
You almost certainly want to be using a NaiveDate instead of this type.
This type primarily exists to aid in the construction of DateTimes that
have a timezone by way of the TimeZone datelike constructors (e.g.
TimeZone::ymd).
This type should be considered ambiguous at best, due to the inherent lack of precision required for the time zone resolution.
There are some guarantees on the usage of Date<Tz>:
-
If properly constructed via
TimeZone::ymdand others without an error, the corresponding local date should exist for at least a moment. (It may still have a gap from the offset changes.) -
The
TimeZoneis free to assign anyOffsetto the local date, as long as that offset did occur in given day.For example, if
2015-03-08T01:59-08:00is followed by2015-03-08T03:00-07:00, it may produce either2015-03-08-08:00or2015-03-08-07:00but not2015-03-08+00:00and others. -
Once constructed as a full
DateTime,DateTime::dateand other associated methods should return those for the originalDate. For example, ifdt = tz.ymd_opt(y,m,d).unwrap().hms(h,n,s)were valid,dt.date() == tz.ymd_opt(y,m,d).unwrap(). -
The date is timezone-agnostic up to one day (i.e. practically always), so the local date and UTC date should be equal for most cases even though the raw calculation between
NaiveDateandTimeDeltamay not.
Implementations§
Source§impl<Tz> Date<Tz>where
Tz: TimeZone,
impl<Tz> Date<Tz>where
Tz: TimeZone,
Sourcepub fn from_utc(date: NaiveDate, offset: <Tz as TimeZone>::Offset) -> Date<Tz>
pub fn from_utc(date: NaiveDate, offset: <Tz as TimeZone>::Offset) -> Date<Tz>
Makes a new Date with given UTC date and offset.
The local date should be constructed via the TimeZone trait.
Sourcepub fn and_time(&self, time: NaiveTime) -> Option<DateTime<Tz>>
pub fn and_time(&self, time: NaiveTime) -> Option<DateTime<Tz>>
Makes a new DateTime from the current date and given NaiveTime.
The offset in the current date is preserved.
Returns None on invalid datetime.
Sourcepub fn and_hms(&self, hour: u32, min: u32, sec: u32) -> DateTime<Tz>
👎Deprecated since 0.4.23: Use and_hms_opt() instead
pub fn and_hms(&self, hour: u32, min: u32, sec: u32) -> DateTime<Tz>
Makes a new DateTime from the current date, hour, minute and second.
The offset in the current date is preserved.
Panics on invalid hour, minute and/or second.
Sourcepub fn and_hms_opt(&self, hour: u32, min: u32, sec: u32) -> Option<DateTime<Tz>>
pub fn and_hms_opt(&self, hour: u32, min: u32, sec: u32) -> Option<DateTime<Tz>>
Makes a new DateTime from the current date, hour, minute and second.
The offset in the current date is preserved.
Returns None on invalid hour, minute and/or second.
Sourcepub fn and_hms_milli(
&self,
hour: u32,
min: u32,
sec: u32,
milli: u32,
) -> DateTime<Tz>
👎Deprecated since 0.4.23: Use and_hms_milli_opt() instead
pub fn and_hms_milli( &self, hour: u32, min: u32, sec: u32, milli: u32, ) -> DateTime<Tz>
Makes a new DateTime from the current date, hour, minute, second and millisecond.
The millisecond part can exceed 1,000 in order to represent the leap second.
The offset in the current date is preserved.
Panics on invalid hour, minute, second and/or millisecond.
Sourcepub fn and_hms_milli_opt(
&self,
hour: u32,
min: u32,
sec: u32,
milli: u32,
) -> Option<DateTime<Tz>>
pub fn and_hms_milli_opt( &self, hour: u32, min: u32, sec: u32, milli: u32, ) -> Option<DateTime<Tz>>
Makes a new DateTime from the current date, hour, minute, second and millisecond.
The millisecond part can exceed 1,000 in order to represent the leap second.
The offset in the current date is preserved.
Returns None on invalid hour, minute, second and/or millisecond.
Sourcepub fn and_hms_micro(
&self,
hour: u32,
min: u32,
sec: u32,
micro: u32,
) -> DateTime<Tz>
👎Deprecated since 0.4.23: Use and_hms_micro_opt() instead
pub fn and_hms_micro( &self, hour: u32, min: u32, sec: u32, micro: u32, ) -> DateTime<Tz>
Makes a new DateTime from the current date, hour, minute, second and microsecond.
The microsecond part can exceed 1,000,000 in order to represent the leap second.
The offset in the current date is preserved.
Panics on invalid hour, minute, second and/or microsecond.
Sourcepub fn and_hms_micro_opt(
&self,
hour: u32,
min: u32,
sec: u32,
micro: u32,
) -> Option<DateTime<Tz>>
pub fn and_hms_micro_opt( &self, hour: u32, min: u32, sec: u32, micro: u32, ) -> Option<DateTime<Tz>>
Makes a new DateTime from the current date, hour, minute, second and microsecond.
The microsecond part can exceed 1,000,000 in order to represent the leap second.
The offset in the current date is preserved.
Returns None on invalid hour, minute, second and/or microsecond.
Sourcepub fn and_hms_nano(
&self,
hour: u32,
min: u32,
sec: u32,
nano: u32,
) -> DateTime<Tz>
👎Deprecated since 0.4.23: Use and_hms_nano_opt() instead
pub fn and_hms_nano( &self, hour: u32, min: u32, sec: u32, nano: u32, ) -> DateTime<Tz>
Makes a new DateTime from the current date, hour, minute, second and nanosecond.
The nanosecond part can exceed 1,000,000,000 in order to represent the leap second.
The offset in the current date is preserved.
Panics on invalid hour, minute, second and/or nanosecond.
Sourcepub fn and_hms_nano_opt(
&self,
hour: u32,
min: u32,
sec: u32,
nano: u32,
) -> Option<DateTime<Tz>>
pub fn and_hms_nano_opt( &self, hour: u32, min: u32, sec: u32, nano: u32, ) -> Option<DateTime<Tz>>
Makes a new DateTime from the current date, hour, minute, second and nanosecond.
The nanosecond part can exceed 1,000,000,000 in order to represent the leap second.
The offset in the current date is preserved.
Returns None on invalid hour, minute, second and/or nanosecond.
Sourcepub fn succ(&self) -> Date<Tz>
👎Deprecated since 0.4.23: Use succ_opt() instead
pub fn succ(&self) -> Date<Tz>
Makes a new Date for the next date.
Panics when self is the last representable date.
Sourcepub fn succ_opt(&self) -> Option<Date<Tz>>
pub fn succ_opt(&self) -> Option<Date<Tz>>
Makes a new Date for the next date.
Returns None when self is the last representable date.
Sourcepub fn pred(&self) -> Date<Tz>
👎Deprecated since 0.4.23: Use pred_opt() instead
pub fn pred(&self) -> Date<Tz>
Makes a new Date for the prior date.
Panics when self is the first representable date.
Sourcepub fn pred_opt(&self) -> Option<Date<Tz>>
pub fn pred_opt(&self) -> Option<Date<Tz>>
Makes a new Date for the prior date.
Returns None when self is the first representable date.
Sourcepub fn with_timezone<Tz2>(&self, tz: &Tz2) -> Date<Tz2>where
Tz2: TimeZone,
pub fn with_timezone<Tz2>(&self, tz: &Tz2) -> Date<Tz2>where
Tz2: TimeZone,
Changes the associated time zone.
This does not change the actual Date (but will change the string representation).
Sourcepub fn checked_add_signed(self, rhs: TimeDelta) -> Option<Date<Tz>>
pub fn checked_add_signed(self, rhs: TimeDelta) -> Option<Date<Tz>>
Adds given TimeDelta to the current date.
Returns None when it will result in overflow.
Sourcepub fn checked_sub_signed(self, rhs: TimeDelta) -> Option<Date<Tz>>
pub fn checked_sub_signed(self, rhs: TimeDelta) -> Option<Date<Tz>>
Subtracts given TimeDelta from the current date.
Returns None when it will result in overflow.
Sourcepub fn signed_duration_since<Tz2>(self, rhs: Date<Tz2>) -> TimeDeltawhere
Tz2: TimeZone,
pub fn signed_duration_since<Tz2>(self, rhs: Date<Tz2>) -> TimeDeltawhere
Tz2: TimeZone,
Subtracts another Date from the current date.
Returns a TimeDelta of integral numbers.
This does not overflow or underflow at all,
as all possible output fits in the range of TimeDelta.
Sourcepub fn naive_local(&self) -> NaiveDate
pub fn naive_local(&self) -> NaiveDate
Returns a view to the naive local date.
This is technically the same as naive_utc
because the offset is restricted to never exceed one day,
but provided for the consistency.
Sourcepub fn years_since(&self, base: Date<Tz>) -> Option<u32>
pub fn years_since(&self, base: Date<Tz>) -> Option<u32>
Returns the number of whole years from the given base until self.
Source§impl<Tz> Date<Tz>
impl<Tz> Date<Tz>
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 date with the specified formatting items.
Sourcepub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
Formats the date with the specified format string.
See the crate::format::strftime module
on the supported escape sequences.
Trait Implementations§
Source§impl<Tz> AddAssign<TimeDelta> for Date<Tz>where
Tz: TimeZone,
impl<Tz> AddAssign<TimeDelta> for Date<Tz>where
Tz: TimeZone,
Source§fn add_assign(&mut self, rhs: TimeDelta)
fn add_assign(&mut self, rhs: TimeDelta)
+= operation. Read moreSource§impl<Tz> Datelike for Date<Tz>where
Tz: TimeZone,
impl<Tz> Datelike for Date<Tz>where
Tz: TimeZone,
Source§fn year(&self) -> i32
fn year(&self) -> i32
Source§fn with_year(&self, year: i32) -> Option<Date<Tz>>
fn with_year(&self, year: i32) -> Option<Date<Tz>>
Source§fn with_month(&self, month: u32) -> Option<Date<Tz>>
fn with_month(&self, month: u32) -> Option<Date<Tz>>
Source§fn with_month0(&self, month0: u32) -> Option<Date<Tz>>
fn with_month0(&self, month0: u32) -> Option<Date<Tz>>
Source§fn with_day(&self, day: u32) -> Option<Date<Tz>>
fn with_day(&self, day: u32) -> Option<Date<Tz>>
Source§fn with_day0(&self, day0: u32) -> Option<Date<Tz>>
fn with_day0(&self, day0: u32) -> Option<Date<Tz>>
Source§fn with_ordinal(&self, ordinal: u32) -> Option<Date<Tz>>
fn with_ordinal(&self, ordinal: u32) -> Option<Date<Tz>>
Source§fn with_ordinal0(&self, ordinal0: u32) -> Option<Date<Tz>>
fn with_ordinal0(&self, ordinal0: u32) -> Option<Date<Tz>>
Source§fn year_ce(&self) -> (bool, u32)
fn year_ce(&self) -> (bool, u32)
Source§fn num_days_from_ce(&self) -> i32
fn num_days_from_ce(&self) -> i32
Source§fn num_days_in_month(&self) -> u8
fn num_days_in_month(&self) -> u8
Source§impl<Tz> Ord for Date<Tz>where
Tz: TimeZone,
impl<Tz> Ord for Date<Tz>where
Tz: TimeZone,
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<Tz> PartialOrd for Date<Tz>where
Tz: TimeZone,
impl<Tz> PartialOrd for Date<Tz>where
Tz: TimeZone,
Source§impl<Tz> SubAssign<TimeDelta> for Date<Tz>where
Tz: TimeZone,
impl<Tz> SubAssign<TimeDelta> for Date<Tz>where
Tz: TimeZone,
Source§fn sub_assign(&mut self, rhs: TimeDelta)
fn sub_assign(&mut self, rhs: TimeDelta)
-= operation. Read moreimpl<Tz> Copy for Date<Tz>
impl<Tz> Eq for Date<Tz>where
Tz: TimeZone,
impl<Tz> Send for Date<Tz>
Auto Trait Implementations§
impl<Tz> Freeze for Date<Tz>
impl<Tz> RefUnwindSafe for Date<Tz>
impl<Tz> Sync for Date<Tz>
impl<Tz> Unpin for Date<Tz>
impl<Tz> UnwindSafe for Date<Tz>
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§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 moreSource§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 moreSource§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
Source§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
Source§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.Source§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.Source§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.Source§impl<T> PipeAsRef for T
impl<T> PipeAsRef for T
Source§impl<T> PipeBorrow for T
impl<T> PipeBorrow for T
Source§impl<T> PipeDeref for T
impl<T> PipeDeref for T
Source§impl<T> PipeRef for T
impl<T> PipeRef for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
Source§fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
tap in debug builds, and does nothing in release builds.Source§fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
Source§fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
tap_mut in debug builds, and does nothing in release builds.Source§impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
Source§fn tap_ref<F, R>(self, func: F) -> Self
fn tap_ref<F, R>(self, func: F) -> Self
Source§fn tap_ref_dbg<F, R>(self, func: F) -> Self
fn tap_ref_dbg<F, R>(self, func: F) -> Self
tap_ref in debug builds, and does nothing in release builds.Source§fn tap_ref_mut<F, R>(self, func: F) -> Self
fn tap_ref_mut<F, R>(self, func: F) -> Self
Source§impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
Source§fn tap_borrow<F, R>(self, func: F) -> Self
fn tap_borrow<F, R>(self, func: F) -> Self
Source§fn tap_borrow_dbg<F, R>(self, func: F) -> Self
fn tap_borrow_dbg<F, R>(self, func: F) -> Self
tap_borrow in debug builds, and does nothing in release builds.Source§fn tap_borrow_mut<F, R>(self, func: F) -> Self
fn tap_borrow_mut<F, R>(self, func: F) -> Self
Source§impl<T> TapDeref for T
impl<T> TapDeref for T
Source§fn tap_deref_dbg<F, R>(self, func: F) -> Self
fn tap_deref_dbg<F, R>(self, func: F) -> Self
tap_deref in debug builds, and does nothing in release builds.Source§fn tap_deref_mut<F, R>(self, func: F) -> Self
fn tap_deref_mut<F, R>(self, func: F) -> Self
self for modification.