Struct chrono::Date

source ·
pub struct Date<Tz: TimeZone> { /* private fields */ }
👎Deprecated since 0.4.23: Use NaiveDate or DateTime<Tz> instead
Expand 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 any Offset 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 by 2015-03-08T03:00-07:00, it may produce either 2015-03-08-08:00 or 2015-03-08-07:00 but not 2015-03-08+00:00 and others.

  • Once constructed as a full DateTime, DateTime::date and other associated methods should return those for the original Date. For example, if dt = 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 and TimeDelta may not.

Implementations§

source§

impl<Tz: TimeZone> Date<Tz>

source

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.

source

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.

source

pub fn and_hms(&self, hour: u32, min: u32, sec: u32) -> DateTime<Tz>

👎Deprecated since 0.4.23: Use and_hms_opt() instead

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.

source

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.

source

pub 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

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.

source

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.

source

pub 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

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.

source

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.

source

pub 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

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.

source

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.

source

pub fn succ(&self) -> Date<Tz>

👎Deprecated since 0.4.23: Use succ_opt() instead

Makes a new Date for the next date.

Panics when self is the last representable date.

source

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.

source

pub fn pred(&self) -> Date<Tz>

👎Deprecated since 0.4.23: Use pred_opt() instead

Makes a new Date for the prior date.

Panics when self is the first representable date.

source

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.

source

pub fn offset(&self) -> &Tz::Offset

Retrieves an associated offset from UTC.

source

pub fn timezone(&self) -> Tz

Retrieves an associated time zone.

source

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).

source

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.

source

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.

source

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.

source

pub fn naive_utc(&self) -> NaiveDate

Returns a view to the naive UTC date.

source

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.

source

pub fn years_since(&self, base: Self) -> Option<u32>

Returns the number of whole years from the given base until self.

source

pub const MIN_UTC: Date<Utc> = _

The minimum possible Date.

source

pub const MAX_UTC: Date<Utc> = _

The maximum possible Date.

source§

impl<Tz: TimeZone> Date<Tz>
where Tz::Offset: Display,

source

pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
where I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>,

Available on crate feature alloc only.

Formats the date with the specified formatting items.

source

pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>

Available on crate feature alloc only.

Formats the date with the specified format string. See the crate::format::strftime module on the supported escape sequences.

source

pub fn format_localized_with_items<'a, I, B>( &self, items: I, locale: Locale ) -> DelayedFormat<I>
where I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>,

Available on crate features unstable-locales and alloc only.

Formats the date with the specified formatting items and locale.

source

pub fn format_localized<'a>( &self, fmt: &'a str, locale: Locale ) -> DelayedFormat<StrftimeItems<'a>>

Available on crate features 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> Add<TimeDelta> for Date<Tz>

§

type Output = Date<Tz>

The resulting type after applying the + operator.
source§

fn add(self, rhs: TimeDelta) -> Date<Tz>

Performs the + operation. Read more
source§

impl<Tz: TimeZone> AddAssign<TimeDelta> for Date<Tz>

source§

fn add_assign(&mut self, rhs: TimeDelta)

Performs the += operation. Read more
source§

impl<'a, Tz> Arbitrary<'a> for Date<Tz>
where Tz: TimeZone, <Tz as TimeZone>::Offset: Arbitrary<'a>,

Available on crate features arbitrary and std only.
source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Date<Tz>>

Generate an arbitrary value of Self from the given unstructured data. Read more
source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
source§

impl<Tz: TimeZone> Archive for Date<Tz>

§

type Archived = ArchivedDate<Tz>

The archived representation of this type. Read more
§

type Resolver = DateResolver<Tz>

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
source§

unsafe fn resolve( &self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived )

Creates the archived version of this value at the given position and writes it to the given output. Read more
source§

impl<Tz: Clone + TimeZone> Clone for Date<Tz>
where Tz::Offset: Clone,

source§

fn clone(&self) -> Date<Tz>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Tz: TimeZone> Datelike for Date<Tz>

source§

fn year(&self) -> i32

Returns the year number in the calendar date.
source§

fn month(&self) -> u32

Returns the month number starting from 1. Read more
source§

fn month0(&self) -> u32

Returns the month number starting from 0. Read more
source§

fn day(&self) -> u32

Returns the day of month starting from 1. Read more
source§

fn day0(&self) -> u32

Returns the day of month starting from 0. Read more
source§

fn ordinal(&self) -> u32

Returns the day of year starting from 1. Read more
source§

fn ordinal0(&self) -> u32

Returns the day of year starting from 0. Read more
source§

fn weekday(&self) -> Weekday

Returns the day of week.
source§

fn iso_week(&self) -> IsoWeek

Returns the ISO week.
source§

fn with_year(&self, year: i32) -> Option<Date<Tz>>

Makes a new value with the year number changed, while keeping the same month and day. Read more
source§

fn with_month(&self, month: u32) -> Option<Date<Tz>>

Makes a new value with the month number (starting from 1) changed. Read more
source§

fn with_month0(&self, month0: u32) -> Option<Date<Tz>>

Makes a new value with the month number (starting from 0) changed. Read more
source§

fn with_day(&self, day: u32) -> Option<Date<Tz>>

Makes a new value with the day of month (starting from 1) changed. Read more
source§

fn with_day0(&self, day0: u32) -> Option<Date<Tz>>

Makes a new value with the day of month (starting from 0) changed. Read more
source§

fn with_ordinal(&self, ordinal: u32) -> Option<Date<Tz>>

Makes a new value with the day of year (starting from 1) changed. Read more
source§

fn with_ordinal0(&self, ordinal0: u32) -> Option<Date<Tz>>

Makes a new value with the day of year (starting from 0) changed. Read more
source§

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).
source§

fn num_days_from_ce(&self) -> i32

Counts the days in the proleptic Gregorian calendar, with January 1, Year 1 (CE) as day 1. Read more
source§

impl<Tz: TimeZone> Debug for Date<Tz>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<__D: Fallible + ?Sized, Tz: TimeZone> Deserialize<Date<Tz>, __D> for Archived<Date<Tz>>

source§

fn deserialize(&self, deserializer: &mut __D) -> Result<Date<Tz>, __D::Error>

Deserializes using the given deserializer
source§

impl<Tz: TimeZone> Display for Date<Tz>
where Tz::Offset: Display,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Tz: TimeZone> Hash for Date<Tz>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<Tz: TimeZone> Ord for Date<Tz>

source§

fn cmp(&self, other: &Date<Tz>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<Tz: TimeZone, Tz2: TimeZone> PartialEq<Date<Tz2>> for Date<Tz>

source§

fn eq(&self, other: &Date<Tz2>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Tz: TimeZone> PartialOrd for Date<Tz>

source§

fn partial_cmp(&self, other: &Date<Tz>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<__S: Fallible + ?Sized, Tz: TimeZone> Serialize<__S> for Date<Tz>
where NaiveDate: Serialize<__S>, Tz::Offset: Serialize<__S>,

source§

fn serialize(&self, serializer: &mut __S) -> Result<Self::Resolver, __S::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.
source§

impl<Tz: TimeZone> Sub<TimeDelta> for Date<Tz>

§

type Output = Date<Tz>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: TimeDelta) -> Date<Tz>

Performs the - operation. Read more
source§

impl<Tz: TimeZone> Sub for Date<Tz>

§

type Output = TimeDelta

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Date<Tz>) -> TimeDelta

Performs the - operation. Read more
source§

impl<Tz: TimeZone> SubAssign<TimeDelta> for Date<Tz>

source§

fn sub_assign(&mut self, rhs: TimeDelta)

Performs the -= operation. Read more
source§

impl<Tz: TimeZone> Copy for Date<Tz>
where <Tz as TimeZone>::Offset: Copy,

source§

impl<Tz: TimeZone> Eq for Date<Tz>

source§

impl<Tz: TimeZone> Send for Date<Tz>
where <Tz as TimeZone>::Offset: Send,

Auto Trait Implementations§

§

impl<Tz> Freeze for Date<Tz>
where <Tz as TimeZone>::Offset: Freeze,

§

impl<Tz> RefUnwindSafe for Date<Tz>
where <Tz as TimeZone>::Offset: RefUnwindSafe,

§

impl<Tz> Sync for Date<Tz>
where <Tz as TimeZone>::Offset: Sync,

§

impl<Tz> Unpin for Date<Tz>
where <Tz as TimeZone>::Offset: Unpin,

§

impl<Tz> UnwindSafe for Date<Tz>
where <Tz as TimeZone>::Offset: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> ArchiveUnsized for T
where T: Archive,

§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
§

type MetadataResolver = ()

The resolver for the metadata of this type. Read more
source§

unsafe fn resolve_metadata( &self, _: usize, _: <T as ArchiveUnsized>::MetadataResolver, _: *mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata )

Creates the archived version of the metadata for this value at the given position and writes it to the given output. Read more
source§

unsafe fn resolve_unsized( &self, from: usize, to: usize, resolver: Self::MetadataResolver, out: *mut RelPtr<Self::Archived, <isize as Archive>::Archived> )

Resolves a relative pointer to this value with the given from and to and writes it to the given output. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Serializer + ?Sized,

source§

fn serialize_unsized( &self, serializer: &mut S ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived type.
source§

fn serialize_metadata(&self, _: &mut S) -> Result<(), <S as Fallible>::Error>

Serializes the metadata for the given type.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.