pub struct Date<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::ymd
and 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
TimeZone
is free to assign anyOffset
to the local date, as long as that offset did occur in given day.For example, if
2015-03-08T01:59-08:00
is followed by2015-03-08T03:00-07:00
, it may produce either2015-03-08-08:00
or2015-03-08-07:00
but not2015-03-08+00:00
and others. -
Once constructed as a full
DateTime
,DateTime::date
and 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
NaiveDate
andTimeDelta
may not.
Implementations§
source§impl<Tz: TimeZone> Date<Tz>
impl<Tz: TimeZone> Date<Tz>
sourcepub fn from_utc(date: NaiveDate, offset: Tz::Offset) -> Date<Tz>
pub fn from_utc(date: NaiveDate, offset: Tz::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: TimeZone>(&self, tz: &Tz2) -> Date<Tz2>
pub fn with_timezone<Tz2: TimeZone>(&self, tz: &Tz2) -> Date<Tz2>
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: TimeZone>(self, rhs: Date<Tz2>) -> TimeDelta
pub fn signed_duration_since<Tz2: TimeZone>(self, rhs: Date<Tz2>) -> TimeDelta
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: Self) -> Option<u32>
pub fn years_since(&self, base: Self) -> Option<u32>
Returns the number of whole years from the given base
until self
.
source§impl<Tz: TimeZone> Date<Tz>
impl<Tz: TimeZone> Date<Tz>
sourcepub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
Available on crate feature alloc
only.
pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
alloc
only.Formats the date with the specified formatting items.
sourcepub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
Available on crate feature alloc
only.
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
alloc
only.Formats the date with the specified format string.
See the crate::format::strftime
module
on the supported escape sequences.
sourcepub fn format_localized_with_items<'a, I, B>(
&self,
items: I,
locale: Locale
) -> DelayedFormat<I>
Available on crate features unstable-locales
and alloc
only.
pub fn format_localized_with_items<'a, I, B>( &self, items: I, locale: Locale ) -> DelayedFormat<I>
unstable-locales
and alloc
only.Formats the date with the specified formatting items and locale.
sourcepub fn format_localized<'a>(
&self,
fmt: &'a str,
locale: Locale
) -> DelayedFormat<StrftimeItems<'a>>
Available on crate features unstable-locales
and alloc
only.
pub fn format_localized<'a>( &self, fmt: &'a str, locale: Locale ) -> DelayedFormat<StrftimeItems<'a>>
unstable-locales
and alloc
only.Formats the date with the specified format string and locale.
See the crate::format::strftime
module
on the supported escape sequences.
Trait Implementations§
source§impl<Tz: TimeZone> AddAssign<TimeDelta> for Date<Tz>
impl<Tz: TimeZone> AddAssign<TimeDelta> for Date<Tz>
source§fn add_assign(&mut self, rhs: TimeDelta)
fn add_assign(&mut self, rhs: TimeDelta)
+=
operation. Read moresource§impl<'a, Tz> Arbitrary<'a> for Date<Tz>
Available on crate features arbitrary
and std
only.
impl<'a, Tz> Arbitrary<'a> for Date<Tz>
arbitrary
and std
only.source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Date<Tz>>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Date<Tz>>
Self
from the given unstructured data. Read moresource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self
from the entirety of the given
unstructured data. Read moresource§impl<Tz: TimeZone> Archive for Date<Tz>
impl<Tz: TimeZone> Archive for Date<Tz>
source§impl<Tz: TimeZone> Datelike for Date<Tz>
impl<Tz: TimeZone> Datelike for Date<Tz>
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§impl<Tz: TimeZone> Ord for Date<Tz>
impl<Tz: TimeZone> Ord for Date<Tz>
source§impl<Tz: TimeZone, Tz2: TimeZone> PartialEq<Date<Tz2>> for Date<Tz>
impl<Tz: TimeZone, Tz2: TimeZone> PartialEq<Date<Tz2>> for Date<Tz>
source§impl<Tz: TimeZone> PartialOrd for Date<Tz>
impl<Tz: TimeZone> PartialOrd for Date<Tz>
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<Tz: TimeZone> SubAssign<TimeDelta> for Date<Tz>
impl<Tz: TimeZone> SubAssign<TimeDelta> for Date<Tz>
source§fn sub_assign(&mut self, rhs: TimeDelta)
fn sub_assign(&mut self, rhs: TimeDelta)
-=
operation. Read moreimpl<Tz: TimeZone> Copy for Date<Tz>
impl<Tz: TimeZone> Eq for Date<Tz>
impl<Tz: TimeZone> 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> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive
, it may be unsized. Read more