Struct Date
struct Date<Tz: TimeZone> { ... }
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
impl<Tz: TimeZone> Date<Tz>
fn format_with_items<'a, I, B>(self: &Self, items: I) -> DelayedFormat<I> where I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>Formats the date with the specified formatting items.
fn format<'a>(self: &Self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>Formats the date with the specified format string. See the
crate::format::strftimemodule on the supported escape sequences.
impl<Tz: TimeZone> Date<Tz>
fn from_utc(date: NaiveDate, offset: <Tz as >::Offset) -> Date<Tz>Makes a new
Datewith given UTC date and offset. The local date should be constructed via theTimeZonetrait.fn and_time(self: &Self, time: NaiveTime) -> Option<DateTime<Tz>>Makes a new
DateTimefrom the current date and givenNaiveTime. The offset in the current date is preserved.Returns
Noneon invalid datetime.fn and_hms(self: &Self, hour: u32, min: u32, sec: u32) -> DateTime<Tz>Makes a new
DateTimefrom the current date, hour, minute and second. The offset in the current date is preserved.Panics on invalid hour, minute and/or second.
fn and_hms_opt(self: &Self, hour: u32, min: u32, sec: u32) -> Option<DateTime<Tz>>Makes a new
DateTimefrom the current date, hour, minute and second. The offset in the current date is preserved.Returns
Noneon invalid hour, minute and/or second.fn and_hms_milli(self: &Self, hour: u32, min: u32, sec: u32, milli: u32) -> DateTime<Tz>Makes a new
DateTimefrom 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.
fn and_hms_milli_opt(self: &Self, hour: u32, min: u32, sec: u32, milli: u32) -> Option<DateTime<Tz>>Makes a new
DateTimefrom 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
Noneon invalid hour, minute, second and/or millisecond.fn and_hms_micro(self: &Self, hour: u32, min: u32, sec: u32, micro: u32) -> DateTime<Tz>Makes a new
DateTimefrom 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.
fn and_hms_micro_opt(self: &Self, hour: u32, min: u32, sec: u32, micro: u32) -> Option<DateTime<Tz>>Makes a new
DateTimefrom 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
Noneon invalid hour, minute, second and/or microsecond.fn and_hms_nano(self: &Self, hour: u32, min: u32, sec: u32, nano: u32) -> DateTime<Tz>Makes a new
DateTimefrom 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.
fn and_hms_nano_opt(self: &Self, hour: u32, min: u32, sec: u32, nano: u32) -> Option<DateTime<Tz>>Makes a new
DateTimefrom 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
Noneon invalid hour, minute, second and/or nanosecond.fn succ(self: &Self) -> Date<Tz>Makes a new
Datefor the next date.Panics when
selfis the last representable date.fn succ_opt(self: &Self) -> Option<Date<Tz>>Makes a new
Datefor the next date.Returns
Nonewhenselfis the last representable date.fn pred(self: &Self) -> Date<Tz>Makes a new
Datefor the prior date.Panics when
selfis the first representable date.fn pred_opt(self: &Self) -> Option<Date<Tz>>Makes a new
Datefor the prior date.Returns
Nonewhenselfis the first representable date.fn offset(self: &Self) -> &<Tz as >::OffsetRetrieves an associated offset from UTC.
fn timezone(self: &Self) -> TzRetrieves an associated time zone.
fn with_timezone<Tz2: TimeZone>(self: &Self, tz: &Tz2) -> Date<Tz2>Changes the associated time zone. This does not change the actual
Date(but will change the string representation).fn checked_add_signed(self: Self, rhs: TimeDelta) -> Option<Date<Tz>>Adds given
TimeDeltato the current date.Returns
Nonewhen it will result in overflow.fn checked_sub_signed(self: Self, rhs: TimeDelta) -> Option<Date<Tz>>Subtracts given
TimeDeltafrom the current date.Returns
Nonewhen it will result in overflow.fn signed_duration_since<Tz2: TimeZone>(self: Self, rhs: Date<Tz2>) -> TimeDeltaSubtracts another
Datefrom the current date. Returns aTimeDeltaof integral numbers.This does not overflow or underflow at all, as all possible output fits in the range of
TimeDelta.fn naive_utc(self: &Self) -> NaiveDateReturns a view to the naive UTC date.
fn naive_local(self: &Self) -> NaiveDateReturns a view to the naive local date.
This is technically the same as
naive_utcbecause the offset is restricted to never exceed one day, but provided for the consistency.fn years_since(self: &Self, base: Self) -> Option<u32>Returns the number of whole years from the given
baseuntilself.
impl<T> Any for Date<Tz>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Date<Tz>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Date<Tz>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Date<Tz>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Date<Tz>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Date<Tz>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for Date<Tz>
fn to_string(self: &Self) -> String
impl<T, U> Into for Date<Tz>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Date<Tz>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Date<Tz>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
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>
impl<Tz: $crate::clone::Clone + TimeZone> Clone for Date<Tz>
fn clone(self: &Self) -> Date<Tz>
impl<Tz: TimeZone> Add for Date<Tz>
fn add(self: Self, rhs: TimeDelta) -> Date<Tz>
impl<Tz: TimeZone> AddAssign for Date<Tz>
fn add_assign(self: &mut Self, rhs: TimeDelta)
impl<Tz: TimeZone> Copy for Date<Tz>
impl<Tz: TimeZone> Datelike for Date<Tz>
fn year(self: &Self) -> i32fn month(self: &Self) -> u32fn month0(self: &Self) -> u32fn day(self: &Self) -> u32fn day0(self: &Self) -> u32fn ordinal(self: &Self) -> u32fn ordinal0(self: &Self) -> u32fn weekday(self: &Self) -> Weekdayfn iso_week(self: &Self) -> IsoWeekfn with_year(self: &Self, year: i32) -> Option<Date<Tz>>fn with_month(self: &Self, month: u32) -> Option<Date<Tz>>fn with_month0(self: &Self, month0: u32) -> Option<Date<Tz>>fn with_day(self: &Self, day: u32) -> Option<Date<Tz>>fn with_day0(self: &Self, day0: u32) -> Option<Date<Tz>>fn with_ordinal(self: &Self, ordinal: u32) -> Option<Date<Tz>>fn with_ordinal0(self: &Self, ordinal0: u32) -> Option<Date<Tz>>
impl<Tz: TimeZone> Debug for Date<Tz>
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl<Tz: TimeZone> Display for Date<Tz>
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl<Tz: TimeZone> Eq for Date<Tz>
impl<Tz: TimeZone> Hash for Date<Tz>
fn hash<H: hash::Hasher>(self: &Self, state: &mut H)
impl<Tz: TimeZone> Ord for Date<Tz>
fn cmp(self: &Self, other: &Date<Tz>) -> Ordering
impl<Tz: TimeZone> PartialOrd for Date<Tz>
fn partial_cmp(self: &Self, other: &Date<Tz>) -> Option<Ordering>
impl<Tz: TimeZone> Send for Date<Tz>
impl<Tz: TimeZone> Sub for Date<Tz>
fn sub(self: Self, rhs: TimeDelta) -> Date<Tz>
impl<Tz: TimeZone> Sub for Date<Tz>
fn sub(self: Self, rhs: Date<Tz>) -> TimeDelta
impl<Tz: TimeZone> SubAssign for Date<Tz>
fn sub_assign(self: &mut Self, rhs: TimeDelta)
impl<Tz: TimeZone, Tz2: TimeZone> PartialEq for Date<Tz>
fn eq(self: &Self, other: &Date<Tz2>) -> bool