[−][src]Struct chrono::Date
ISO 8601 calendar date with time zone.
This type should be considered ambiguous at best,
due to the inherent lack of precision required for the time zone resolution.
For serialization and deserialization uses, it is best to use NaiveDate instead.
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, if2015-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(y,m,d).hms(h,n,s)were valid,dt.date() == tz.ymd(y,m,d). -
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
NaiveDateandDurationmay not.
Methods
impl<Tz: TimeZone> Date<Tz>[src]
impl<Tz: TimeZone> Date<Tz>pub fn from_utc(date: NaiveDate, offset: Tz::Offset) -> Date<Tz>[src]
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.
pub fn and_time(&self, time: NaiveTime) -> Option<DateTime<Tz>>[src]
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.
Panics on invalid datetime.
pub fn and_hms(&self, hour: u32, min: u32, sec: u32) -> DateTime<Tz>[src]
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.
pub fn and_hms_opt(&self, hour: u32, min: u32, sec: u32) -> Option<DateTime<Tz>>[src]
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.
pub fn and_hms_milli(
&self,
hour: u32,
min: u32,
sec: u32,
milli: u32
) -> DateTime<Tz>[src]
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.
pub fn and_hms_milli_opt(
&self,
hour: u32,
min: u32,
sec: u32,
milli: u32
) -> Option<DateTime<Tz>>[src]
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.
pub fn and_hms_micro(
&self,
hour: u32,
min: u32,
sec: u32,
micro: u32
) -> DateTime<Tz>[src]
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.
pub fn and_hms_micro_opt(
&self,
hour: u32,
min: u32,
sec: u32,
micro: u32
) -> Option<DateTime<Tz>>[src]
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.
pub fn and_hms_nano(
&self,
hour: u32,
min: u32,
sec: u32,
nano: u32
) -> DateTime<Tz>[src]
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.
pub fn and_hms_nano_opt(
&self,
hour: u32,
min: u32,
sec: u32,
nano: u32
) -> Option<DateTime<Tz>>[src]
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.
pub fn succ(&self) -> Date<Tz>[src]
pub fn succ(&self) -> Date<Tz>Makes a new Date for the next date.
Panics when self is the last representable date.
pub fn succ_opt(&self) -> Option<Date<Tz>>[src]
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.
pub fn pred(&self) -> Date<Tz>[src]
pub fn pred(&self) -> Date<Tz>Makes a new Date for the prior date.
Panics when self is the first representable date.
pub fn pred_opt(&self) -> Option<Date<Tz>>[src]
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.
pub fn offset(&self) -> &Tz::Offset[src]
pub fn offset(&self) -> &Tz::OffsetRetrieves an associated offset from UTC.
pub fn timezone(&self) -> Tz[src]
pub fn timezone(&self) -> TzRetrieves an associated time zone.
pub fn with_timezone<Tz2: TimeZone>(&self, tz: &Tz2) -> Date<Tz2>[src]
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).
pub fn checked_add_signed(self, rhs: OldDuration) -> Option<Date<Tz>>[src]
pub fn checked_add_signed(self, rhs: OldDuration) -> Option<Date<Tz>>Adds given Duration to the current date.
Returns None when it will result in overflow.
pub fn checked_sub_signed(self, rhs: OldDuration) -> Option<Date<Tz>>[src]
pub fn checked_sub_signed(self, rhs: OldDuration) -> Option<Date<Tz>>Subtracts given Duration from the current date.
Returns None when it will result in overflow.
pub fn signed_duration_since<Tz2: TimeZone>(self, rhs: Date<Tz2>) -> OldDuration[src]
pub fn signed_duration_since<Tz2: TimeZone>(self, rhs: Date<Tz2>) -> OldDurationSubtracts another Date from the current date.
Returns a Duration of integral numbers.
This does not overflow or underflow at all,
as all possible output fits in the range of Duration.
pub fn naive_utc(&self) -> NaiveDate[src]
pub fn naive_utc(&self) -> NaiveDateReturns a view to the naive UTC date.
pub fn naive_local(&self) -> NaiveDate[src]
pub fn naive_local(&self) -> NaiveDateReturns a view to the naive local date.
This is technically same to naive_utc
because the offset is restricted to never exceed one day,
but provided for the consistency.
impl<Tz: TimeZone> Date<Tz> where
Tz::Offset: Display, [src]
impl<Tz: TimeZone> Date<Tz> where
Tz::Offset: Display, pub fn format_with_items<'a, I>(&self, items: I) -> DelayedFormat<I> where
I: Iterator<Item = Item<'a>> + Clone, [src]
pub fn format_with_items<'a, I>(&self, items: I) -> DelayedFormat<I> where
I: Iterator<Item = Item<'a>> + Clone, Formats the date with the specified formatting items.
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>[src]
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>Formats the date with the specified format string.
See the format::strftime module
on the supported escape sequences.
Trait Implementations
impl<Tz: TimeZone> Datelike for Date<Tz>[src]
impl<Tz: TimeZone> Datelike for Date<Tz>fn year(&self) -> i32[src]
fn year(&self) -> i32fn month(&self) -> u32[src]
fn month(&self) -> u32fn month0(&self) -> u32[src]
fn month0(&self) -> u32fn day(&self) -> u32[src]
fn day(&self) -> u32fn day0(&self) -> u32[src]
fn day0(&self) -> u32fn ordinal(&self) -> u32[src]
fn ordinal(&self) -> u32fn ordinal0(&self) -> u32[src]
fn ordinal0(&self) -> u32fn weekday(&self) -> Weekday[src]
fn weekday(&self) -> Weekdayfn iso_week(&self) -> IsoWeek[src]
fn iso_week(&self) -> IsoWeekfn with_year(&self, year: i32) -> Option<Date<Tz>>[src]
fn with_year(&self, year: i32) -> Option<Date<Tz>>fn with_month(&self, month: u32) -> Option<Date<Tz>>[src]
fn with_month(&self, month: u32) -> Option<Date<Tz>>fn with_month0(&self, month0: u32) -> Option<Date<Tz>>[src]
fn with_month0(&self, month0: u32) -> Option<Date<Tz>>fn with_day(&self, day: u32) -> Option<Date<Tz>>[src]
fn with_day(&self, day: u32) -> Option<Date<Tz>>fn with_day0(&self, day0: u32) -> Option<Date<Tz>>[src]
fn with_day0(&self, day0: u32) -> Option<Date<Tz>>fn with_ordinal(&self, ordinal: u32) -> Option<Date<Tz>>[src]
fn with_ordinal(&self, ordinal: u32) -> Option<Date<Tz>>fn with_ordinal0(&self, ordinal0: u32) -> Option<Date<Tz>>[src]
fn with_ordinal0(&self, ordinal0: u32) -> Option<Date<Tz>>fn year_ce(&self) -> (bool, u32)[src]
fn year_ce(&self) -> (bool, u32)Returns the absolute year number starting from 1 with a boolean flag, which is false when the year predates the epoch (BCE/BC) and true otherwise (CE/AD). Read more
fn num_days_from_ce(&self) -> i32[src]
fn num_days_from_ce(&self) -> i32Returns the number of days since January 1, Year 1 (aka Day 1) in the proleptic Gregorian calendar. Read more
impl<Tz: TimeZone, Tz2: TimeZone> PartialEq<Date<Tz2>> for Date<Tz>[src]
impl<Tz: TimeZone, Tz2: TimeZone> PartialEq<Date<Tz2>> for Date<Tz>fn eq(&self, other: &Date<Tz2>) -> bool[src]
fn eq(&self, other: &Date<Tz2>) -> bool#[must_use]
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]
fn ne(&self, other: &Rhs) -> boolThis method tests for !=.
impl<Tz: TimeZone> Send for Date<Tz> where
<Tz as TimeZone>::Offset: Send, [src]
impl<Tz: TimeZone> Send for Date<Tz> where
<Tz as TimeZone>::Offset: Send, impl<Tz: Clone + TimeZone> Clone for Date<Tz> where
Tz::Offset: Clone, [src]
impl<Tz: Clone + TimeZone> Clone for Date<Tz> where
Tz::Offset: Clone, fn clone(&self) -> Date<Tz>[src]
fn clone(&self) -> Date<Tz>fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl<Tz: TimeZone> Copy for Date<Tz> where
<Tz as TimeZone>::Offset: Copy, [src]
impl<Tz: TimeZone> Copy for Date<Tz> where
<Tz as TimeZone>::Offset: Copy, impl<Tz: TimeZone> Ord for Date<Tz>[src]
impl<Tz: TimeZone> Ord for Date<Tz>fn cmp(&self, other: &Date<Tz>) -> Ordering[src]
fn cmp(&self, other: &Date<Tz>) -> Orderingfn max(self, other: Self) -> Self1.21.0[src]
fn max(self, other: Self) -> SelfCompares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self1.21.0[src]
fn min(self, other: Self) -> SelfCompares and returns the minimum of two values. Read more
impl<Tz: TimeZone> Eq for Date<Tz>[src]
impl<Tz: TimeZone> Eq for Date<Tz>impl<Tz: TimeZone> PartialOrd<Date<Tz>> for Date<Tz>[src]
impl<Tz: TimeZone> PartialOrd<Date<Tz>> for Date<Tz>fn partial_cmp(&self, other: &Date<Tz>) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &Date<Tz>) -> Option<Ordering>#[must_use]
fn lt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]
fn lt(&self, other: &Rhs) -> boolThis method tests less than (for self and other) and is used by the < operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> boolThis method tests less than or equal to (for self and other) and is used by the <= operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> boolThis method tests greater than (for self and other) and is used by the > operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> boolThis method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl<Tz: TimeZone> Display for Date<Tz> where
Tz::Offset: Display, [src]
impl<Tz: TimeZone> Display for Date<Tz> where
Tz::Offset: Display, impl<Tz: TimeZone> Debug for Date<Tz>[src]
impl<Tz: TimeZone> Debug for Date<Tz>impl<Tz: TimeZone> Hash for Date<Tz>[src]
impl<Tz: TimeZone> Hash for Date<Tz>fn hash<H: Hasher>(&self, state: &mut H)[src]
fn hash<H: Hasher>(&self, state: &mut H)fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, Feeds a slice of this type into the given [Hasher]. Read more
impl<Tz: TimeZone> Add<Duration> for Date<Tz>[src]
impl<Tz: TimeZone> Add<Duration> for Date<Tz>type Output = Date<Tz>
The resulting type after applying the + operator.
fn add(self, rhs: OldDuration) -> Date<Tz>[src]
fn add(self, rhs: OldDuration) -> Date<Tz>impl<Tz: TimeZone> Sub<Duration> for Date<Tz>[src]
impl<Tz: TimeZone> Sub<Duration> for Date<Tz>type Output = Date<Tz>
The resulting type after applying the - operator.
fn sub(self, rhs: OldDuration) -> Date<Tz>[src]
fn sub(self, rhs: OldDuration) -> Date<Tz>impl<Tz: TimeZone> Sub<Date<Tz>> for Date<Tz>[src]
impl<Tz: TimeZone> Sub<Date<Tz>> for Date<Tz>type Output = OldDuration
The resulting type after applying the - operator.
fn sub(self, rhs: Date<Tz>) -> OldDuration[src]
fn sub(self, rhs: Date<Tz>) -> OldDurationAuto Trait Implementations
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized, [src]
impl<T> ToString for T where
T: Display + ?Sized, impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, impl<T, U> TryFrom for T where
T: From<U>, [src]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeIdimpl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut T