Lines Matching full:date
4 //! ISO 8601 calendar date with time zone.
24 /// ISO 8601 calendar date with time zone.
35 /// There are some guarantees on the usage of `Date<Tz>`:
38 /// the corresponding local date should exist for at least a moment.
42 /// local date, as long as that offset did occur in given day.
48 /// - Once constructed as a full `DateTime`, [`DateTime::date`] and other associated
49 /// methods should return those for the original `Date`. For example, if `dt =
50 /// tz.ymd_opt(y,m,d).unwrap().hms(h,n,s)` were valid, `dt.date() == tz.ymd_opt(y,m,d).unwrap()`.
52 /// - The date is timezone-agnostic up to one day (i.e. practically always),
53 /// so the local date and UTC date should be equal for most cases
58 pub struct Date<Tz: TimeZone> { struct
59 date: NaiveDate, field
63 /// The minimum possible `Date`. argument
65 #[deprecated(since = "0.4.20", note = "Use Date::MIN_UTC instead")]
66 pub const MIN_DATE: Date<Utc> = Date::<Utc>::MIN_UTC;
67 /// The maximum possible `Date`.
69 #[deprecated(since = "0.4.20", note = "Use Date::MAX_UTC instead")]
70 pub const MAX_DATE: Date<Utc> = Date::<Utc>::MAX_UTC;
72 impl<Tz: TimeZone> Date<Tz> { impl
73 /// Makes a new `Date` with given *UTC* date and offset.
74 /// The local date should be constructed via the `TimeZone` trait.
77 pub fn from_utc(date: NaiveDate, offset: Tz::Offset) -> Date<Tz> { in from_utc()
78 Date { date, offset } in from_utc()
81 /// Makes a new `DateTime` from the current date and given `NaiveTime`.
82 /// The offset in the current date is preserved.
92 /// Makes a new `DateTime` from the current date, hour, minute and second.
93 /// The offset in the current date is preserved.
103 /// Makes a new `DateTime` from the current date, hour, minute and second.
104 /// The offset in the current date is preserved.
113 /// Makes a new `DateTime` from the current date, hour, minute, second and millisecond.
115 /// The offset in the current date is preserved.
125 /// Makes a new `DateTime` from the current date, hour, minute, second and millisecond.
127 /// The offset in the current date is preserved.
142 /// Makes a new `DateTime` from the current date, hour, minute, second and microsecond.
144 /// The offset in the current date is preserved.
154 /// Makes a new `DateTime` from the current date, hour, minute, second and microsecond.
156 /// The offset in the current date is preserved.
171 /// Makes a new `DateTime` from the current date, hour, minute, second and nanosecond.
173 /// The offset in the current date is preserved.
183 /// Makes a new `DateTime` from the current date, hour, minute, second and nanosecond.
185 /// The offset in the current date is preserved.
200 /// Makes a new `Date` for the next date.
202 /// Panics when `self` is the last representable date.
206 pub fn succ(&self) -> Date<Tz> { in succ()
210 /// Makes a new `Date` for the next date.
212 /// Returns `None` when `self` is the last representable date.
215 pub fn succ_opt(&self) -> Option<Date<Tz>> { in succ_opt()
216 self.date.succ_opt().map(|date| Date::from_utc(date, self.offset.clone())) in succ_opt()
219 /// Makes a new `Date` for the prior date.
221 /// Panics when `self` is the first representable date.
225 pub fn pred(&self) -> Date<Tz> { in pred()
229 /// Makes a new `Date` for the prior date.
231 /// Returns `None` when `self` is the first representable date.
234 pub fn pred_opt(&self) -> Option<Date<Tz>> { in pred_opt()
235 self.date.pred_opt().map(|date| Date::from_utc(date, self.offset.clone())) in pred_opt()
253 /// This does not change the actual `Date` (but will change the string representation).
256 pub fn with_timezone<Tz2: TimeZone>(&self, tz: &Tz2) -> Date<Tz2> { in with_timezone()
257 tz.from_utc_date(&self.date) in with_timezone()
260 /// Adds given `TimeDelta` to the current date.
265 pub fn checked_add_signed(self, rhs: TimeDelta) -> Option<Date<Tz>> { in checked_add_signed()
266 let date = self.date.checked_add_signed(rhs)?; in checked_add_signed() localVariable
267 Some(Date { date, offset: self.offset }) in checked_add_signed()
270 /// Subtracts given `TimeDelta` from the current date.
275 pub fn checked_sub_signed(self, rhs: TimeDelta) -> Option<Date<Tz>> { in checked_sub_signed()
276 let date = self.date.checked_sub_signed(rhs)?; in checked_sub_signed() localVariable
277 Some(Date { date, offset: self.offset }) in checked_sub_signed()
280 /// Subtracts another `Date` from the current date.
287 pub fn signed_duration_since<Tz2: TimeZone>(self, rhs: Date<Tz2>) -> TimeDelta { in signed_duration_since()
288 self.date.signed_duration_since(rhs.date) in signed_duration_since()
291 /// Returns a view to the naive UTC date.
295 self.date in naive_utc()
298 /// Returns a view to the naive local date.
306 self.date in naive_local()
312 self.date.years_since(base.date) in years_since()
315 /// The minimum possible `Date`.
316 pub const MIN_UTC: Date<Utc> = Date { date: NaiveDate::MIN, offset: Utc };
317 /// The maximum possible `Date`.
318 pub const MAX_UTC: Date<Utc> = Date { date: NaiveDate::MAX, offset: Utc };
321 /// Maps the local date to other date with given conversion function.
322 fn map_local<Tz: TimeZone, F>(d: &Date<Tz>, mut f: F) -> Option<Date<Tz>> in map_local()
326 f(d.naive_local()).and_then(|date| d.timezone().from_local_date(&date).single()) in map_local()
329 impl<Tz: TimeZone> Date<Tz> implementation
333 /// Formats the date with the specified formatting items.
345 /// Formats the date with the specified format string.
355 /// Formats the date with the specified formatting items and locale.
377 /// Formats the date with the specified format string and locale.
392 impl<Tz: TimeZone> Datelike for Date<Tz> { implementation
431 fn with_year(&self, year: i32) -> Option<Date<Tz>> { in with_year()
432 map_local(self, |date| date.with_year(year)) in with_year()
436 fn with_month(&self, month: u32) -> Option<Date<Tz>> { in with_month()
437 map_local(self, |date| date.with_month(month)) in with_month()
441 fn with_month0(&self, month0: u32) -> Option<Date<Tz>> { in with_month0()
442 map_local(self, |date| date.with_month0(month0)) in with_month0()
446 fn with_day(&self, day: u32) -> Option<Date<Tz>> { in with_day()
447 map_local(self, |date| date.with_day(day)) in with_day()
451 fn with_day0(&self, day0: u32) -> Option<Date<Tz>> { in with_day0()
452 map_local(self, |date| date.with_day0(day0)) in with_day0()
456 fn with_ordinal(&self, ordinal: u32) -> Option<Date<Tz>> { in with_ordinal()
457 map_local(self, |date| date.with_ordinal(ordinal)) in with_ordinal()
461 fn with_ordinal0(&self, ordinal0: u32) -> Option<Date<Tz>> { in with_ordinal0()
462 map_local(self, |date| date.with_ordinal0(ordinal0)) in with_ordinal0()
467 impl<Tz: TimeZone> Copy for Date<Tz> where <Tz as TimeZone>::Offset: Copy {} implementation
468 unsafe impl<Tz: TimeZone> Send for Date<Tz> where <Tz as TimeZone>::Offset: Send {} implementation
470 impl<Tz: TimeZone, Tz2: TimeZone> PartialEq<Date<Tz2>> for Date<Tz> { implementation
471 fn eq(&self, other: &Date<Tz2>) -> bool { in eq()
472 self.date == other.date in eq()
476 impl<Tz: TimeZone> Eq for Date<Tz> {} implementation
478 impl<Tz: TimeZone> PartialOrd for Date<Tz> { implementation
479 fn partial_cmp(&self, other: &Date<Tz>) -> Option<Ordering> { in partial_cmp()
484 impl<Tz: TimeZone> Ord for Date<Tz> { implementation
485 fn cmp(&self, other: &Date<Tz>) -> Ordering { in cmp()
486 self.date.cmp(&other.date) in cmp()
490 impl<Tz: TimeZone> hash::Hash for Date<Tz> { implementation
492 self.date.hash(state) in hash()
496 impl<Tz: TimeZone> Add<TimeDelta> for Date<Tz> { implementation
497 type Output = Date<Tz>;
500 fn add(self, rhs: TimeDelta) -> Date<Tz> { in add()
501 self.checked_add_signed(rhs).expect("`Date + TimeDelta` overflowed") in add()
505 impl<Tz: TimeZone> AddAssign<TimeDelta> for Date<Tz> { implementation
508 self.date = self.date.checked_add_signed(rhs).expect("`Date + TimeDelta` overflowed"); in add_assign()
512 impl<Tz: TimeZone> Sub<TimeDelta> for Date<Tz> { implementation
513 type Output = Date<Tz>;
516 fn sub(self, rhs: TimeDelta) -> Date<Tz> { in sub()
517 self.checked_sub_signed(rhs).expect("`Date - TimeDelta` overflowed") in sub()
521 impl<Tz: TimeZone> SubAssign<TimeDelta> for Date<Tz> { implementation
524 self.date = self.date.checked_sub_signed(rhs).expect("`Date - TimeDelta` overflowed"); in sub_assign()
528 impl<Tz: TimeZone> Sub<Date<Tz>> for Date<Tz> { implementation
532 fn sub(self, rhs: Date<Tz>) -> TimeDelta { in sub()
537 impl<Tz: TimeZone> fmt::Debug for Date<Tz> { implementation
544 impl<Tz: TimeZone> fmt::Display for Date<Tz> implementation
554 // Note that implementation of Arbitrary cannot be automatically derived for Date<Tz>, due to
557 impl<'a, Tz> arbitrary::Arbitrary<'a> for Date<Tz> implementation
562 fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Date<Tz>> { in arbitrary()
563 let date = NaiveDate::arbitrary(u)?; in arbitrary() localVariable
565 Ok(Date::from_utc(date, offset)) in arbitrary()
571 use super::Date;
599 let date = Date::<Utc>::from_utc(naivedate, Utc); in test_date_add_assign() localVariable
600 let mut date_add = date; in test_date_add_assign()
603 assert_eq!(date_add, date + TimeDelta::days(5)); in test_date_add_assign()
606 let date = date.with_timezone(&timezone); in test_date_add_assign() localVariable
609 assert_eq!(date_add, date + TimeDelta::days(5)); in test_date_add_assign()
612 let date = date.with_timezone(&timezone); in test_date_add_assign() localVariable
615 assert_eq!(date_add, date + TimeDelta::days(5)); in test_date_add_assign()
623 let date = Local.from_utc_date(&naivedate); in test_date_add_assign_local() localVariable
624 let mut date_add = date; in test_date_add_assign_local()
627 assert_eq!(date_add, date + TimeDelta::days(5)); in test_date_add_assign_local()
633 let date = Date::<Utc>::from_utc(naivedate, Utc); in test_date_sub_assign() localVariable
634 let mut date_sub = date; in test_date_sub_assign()
637 assert_eq!(date_sub, date - TimeDelta::days(5)); in test_date_sub_assign()
640 let date = date.with_timezone(&timezone); in test_date_sub_assign() localVariable
643 assert_eq!(date_sub, date - TimeDelta::days(5)); in test_date_sub_assign()
646 let date = date.with_timezone(&timezone); in test_date_sub_assign() localVariable
649 assert_eq!(date_sub, date - TimeDelta::days(5)); in test_date_sub_assign()
657 let date = Local.from_utc_date(&naivedate); in test_date_sub_assign_local() localVariable
658 let mut date_sub = date; in test_date_sub_assign_local()
661 assert_eq!(date_sub, date - TimeDelta::days(5)); in test_date_sub_assign_local()