• Home
  • Raw
  • Download

Lines Matching +full:rkyv +full:- +full:validation

12 #[cfg(any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"))]
13 use rkyv::{Archive, Deserialize, Serialize};
16 #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
63 pub const fn first_day(&self) -> NaiveDate { in first_day()
69 let days = start - ref_day - if start > ref_day { 7 } else { 0 }; in first_day()
91 pub const fn last_day(&self) -> NaiveDate { in last_day()
97 let days = end - ref_day + if end < ref_day { 7 } else { 0 }; in last_day()
121 pub const fn days(&self) -> RangeInclusive<NaiveDate> { in days()
137 pub const fn new(num: u64) -> Self { in new()
156 /// on the same calendar date---April 23, 1616---but in the different calendar.
177 /// Chrono's date types default to the ISO 8601 [calendar date](#calendar-date), but
185 /// The year number is the same as that of the [calendar date](#calendar-date).
189 /// [proleptic Gregorian date]: crate::NaiveDate#calendar-date
192 any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
197 #[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
211 fn arbitrary(u: &mut arbitrary::Unstructured) -> arbitrary::Result<NaiveDate> { in arbitrary()
220 pub(crate) fn weeks_from(&self, day: Weekday) -> i32 { in weeks_from()
221 (self.ordinal() as i32 - self.weekday().num_days_from(day) as i32 + 6) / 7 in weeks_from()
230 ) -> Option<NaiveDate> { in from_ordinal_and_flags()
232 return None; // Out-of-range in from_ordinal_and_flags()
241 /// Makes a new `NaiveDate` from year and packed month-day-flags.
243 const fn from_mdf(year: i32, mdf: Mdf) -> Option<NaiveDate> { in from_mdf()
245 return None; // Out-of-range in from_mdf()
249 None => None, // Non-existing date in from_mdf()
253 /// Makes a new `NaiveDate` from the [calendar date](#calendar-date)
262 pub const fn from_ymd(year: i32, month: u32, day: u32) -> NaiveDate { in from_ymd()
263 expect!(NaiveDate::from_ymd_opt(year, month, day), "invalid or out-of-range date") in from_ymd()
266 /// Makes a new `NaiveDate` from the [calendar date](#calendar-date)
272 /// - The specified calendar day does not exist (for example 2023-04-31).
273 /// - The value for `month` or `day` is invalid.
274 /// - `year` is out of range for `NaiveDate`.
286 /// assert!(from_ymd_opt(-4, 2, 29).is_some()); // 5 BCE is a leap year
288 /// assert!(from_ymd_opt(-400000, 1, 1).is_none());
291 pub const fn from_ymd_opt(year: i32, month: u32, day: u32) -> Option<NaiveDate> { in from_ymd_opt()
301 /// Makes a new `NaiveDate` from the [ordinal date](#ordinal-date)
310 pub const fn from_yo(year: i32, ordinal: u32) -> NaiveDate { in from_yo()
311 expect!(NaiveDate::from_yo_opt(year, ordinal), "invalid or out-of-range date") in from_yo()
314 /// Makes a new `NaiveDate` from the [ordinal date](#ordinal-date)
320 /// - The specified ordinal day does not exist (for example 2023-366).
321 /// - The value for `ordinal` is invalid (for example: `0`, `400`).
322 /// - `year` is out of range for `NaiveDate`.
335 /// assert!(from_yo_opt(-4, 366).is_some()); // 5 BCE is a leap year
337 /// assert!(from_yo_opt(-400000, 1).is_none());
340 pub const fn from_yo_opt(year: i32, ordinal: u32) -> Option<NaiveDate> { in from_yo_opt()
345 /// Makes a new `NaiveDate` from the [ISO week date](#week-date)
355 pub const fn from_isoywd(year: i32, week: u32, weekday: Weekday) -> NaiveDate { in from_isoywd()
356 expect!(NaiveDate::from_isoywd_opt(year, week, weekday), "invalid or out-of-range date") in from_isoywd()
359 /// Makes a new `NaiveDate` from the [ISO week date](#week-date)
366 /// - The specified week does not exist in that year (for example 2023 week 53).
367 /// - The value for `week` is invalid (for example: `0`, `60`).
368 /// - If the resulting date is out of range for `NaiveDate`.
384 /// assert_eq!(from_isoywd_opt(-400000, 10, Weekday::Sat), None);
394 /// // 2014-W52 22 23 24 25 26 27 28 has 4+ days of new year,
395 /// // 2015-W01 29 30 31 1 2 3 4 <- so this is the first week
400 /// // 2015-W52 21 22 23 24 25 26 27 has 4+ days of old year,
401 /// // 2015-W53 28 29 30 31 1 2 3 <- so this is the last week
402 /// // 2016-W01 4 5 6 7 8 9 10
409 pub const fn from_isoywd_opt(year: i32, week: u32, weekday: Weekday) -> Option<NaiveDate> { in from_isoywd_opt()
413 // ordinal = week ordinal - delta in from_isoywd_opt()
418 let prevflags = YearFlags::from_year(year - 1); in from_isoywd_opt()
420 year - 1, in from_isoywd_opt()
421 weekord + prevflags.ndays() - delta, in from_isoywd_opt()
425 let ordinal = weekord - delta; in from_isoywd_opt()
433 NaiveDate::from_ordinal_and_flags(year + 1, ordinal - ndays, nextflags) in from_isoywd_opt()
450 pub const fn from_num_days_from_ce(days: i32) -> NaiveDate { in from_num_days_from_ce()
451 expect!(NaiveDate::from_num_days_from_ce_opt(days), "out-of-range date") in from_num_days_from_ce()
472 /// assert_eq!(from_ndays_opt(-1), Some(from_ymd(0, 12, 30)));
474 /// assert_eq!(from_ndays_opt(-100_000_000), None);
477 pub const fn from_num_days_from_ce_opt(days: i32) -> Option<NaiveDate> { in from_num_days_from_ce_opt()
486 /// Makes a new `NaiveDate` by counting the number of occurrences of a particular day-of-week
490 /// `n` is 1-indexed.
503 ) -> NaiveDate { in from_weekday_of_month()
504 expect!(NaiveDate::from_weekday_of_month_opt(year, month, weekday, n), "out-of-range date") in from_weekday_of_month()
507 /// Makes a new `NaiveDate` by counting the number of occurrences of a particular day-of-week
511 /// `n` is 1-indexed.
516 /// - The specified day does not exist in that month (for example the 5th Monday of Apr. 2023).
517 /// - The value for `month` or `n` is invalid.
518 /// - `year` is out of range for `NaiveDate`.
533 ) -> Option<NaiveDate> { in from_weekday_of_month_opt()
538 let first_to_dow = (7 + weekday.number_from_monday() - first.number_from_monday()) % 7; in from_weekday_of_month_opt()
539 let day = (n - 1) as u32 * 7 + first_to_dow + 1; in from_weekday_of_month_opt()
554 /// assert_eq!(parse_from_str("2015-09-05", "%Y-%m-%d"),
565 /// assert_eq!(parse_from_str("2014-5-17T12:34:56+09:30", "%Y-%m-%dT%H:%M:%S%z"),
569 /// Out-of-bound dates or insufficient fields are errors.
585 pub fn parse_from_str(s: &str, fmt: &str) -> ParseResult<NaiveDate> { in parse_from_str()
591 /// Parses a string from a user-specified format into a new `NaiveDate` value, and a slice with
603 /// "2015-02-18 trailing text", "%Y-%m-%d").unwrap();
607 pub fn parse_and_remainder<'a>(s: &'a str, fmt: &str) -> ParseResult<(NaiveDate, &'a str)> { in parse_and_remainder()
635 pub const fn checked_add_months(self, months: Months) -> Option<Self> { in checked_add_months()
670 pub const fn checked_sub_months(self, months: Months) -> Option<Self> { in checked_sub_months()
677 true => self.diff_months(-(months.0 as i32)), in checked_sub_months()
682 const fn diff_months(self, months: i32) -> Option<Self> { in diff_months()
687 let year = if (years > 0 && years > (MAX_YEAR - self.year())) in diff_months()
688 || (years < 0 && years < (MIN_YEAR - self.year())) in diff_months()
703 (year - 1, month + 12) in diff_months()
709 (year + 1, month - 12) in diff_months()
719 let day_max = days[(month - 1) as usize]; in diff_months()
752 pub const fn checked_add_days(self, days: Days) -> Option<Self> { in checked_add_days()
779 pub const fn checked_sub_days(self, days: Days) -> Option<Self> { in checked_sub_days()
781 true => self.add_days(-(days.0 as i32)), in checked_sub_days()
787 pub(crate) const fn add_days(self, days: i32) -> Option<Self> { in add_days()
825 pub const fn and_time(&self, time: NaiveTime) -> NaiveDateTime { in and_time()
831 /// No [leap second](./struct.NaiveTime.html#leap-second-handling) is allowed here;
840 pub const fn and_hms(&self, hour: u32, min: u32, sec: u32) -> NaiveDateTime { in and_hms()
846 /// No [leap second](./struct.NaiveTime.html#leap-second-handling) is allowed here;
866 pub const fn and_hms_opt(&self, hour: u32, min: u32, sec: u32) -> Option<NaiveDateTime> { in and_hms_opt()
874 /// ./struct.NaiveTime.html#leap-second-handling), but only when `sec == 59`.
882 pub const fn and_hms_milli(&self, hour: u32, min: u32, sec: u32, milli: u32) -> NaiveDateTime { in and_hms_milli()
889 /// ./struct.NaiveTime.html#leap-second-handling), but only when `sec == 59`.
916 ) -> Option<NaiveDateTime> { in and_hms_milli_opt()
924 /// ./struct.NaiveTime.html#leap-second-handling), but only when `sec == 59`.
946 pub const fn and_hms_micro(&self, hour: u32, min: u32, sec: u32, micro: u32) -> NaiveDateTime { in and_hms_micro()
953 /// ./struct.NaiveTime.html#leap-second-handling), but only when `sec == 59`.
980 ) -> Option<NaiveDateTime> { in and_hms_micro_opt()
988 /// ./struct.NaiveTime.html#leap-second-handling), but only when `sec == 59`.
996 pub const fn and_hms_nano(&self, hour: u32, min: u32, sec: u32, nano: u32) -> NaiveDateTime { in and_hms_nano()
1003 /// ./struct.NaiveTime.html#leap-second-handling), but only when `sec == 59`.
1030 ) -> Option<NaiveDateTime> { in and_hms_nano_opt()
1035 /// Returns the packed month-day-flags.
1037 const fn mdf(&self) -> Mdf { in mdf()
1041 /// Returns the packed ordinal-flags.
1043 const fn of(&self) -> Of { in of()
1047 /// Makes a new `NaiveDate` with the packed month-day-flags changed.
1051 const fn with_mdf(&self, mdf: Mdf) -> Option<NaiveDate> { in with_mdf()
1055 /// Makes a new `NaiveDate` with the packed ordinal-flags changed.
1060 const fn with_of(&self, of: Of) -> NaiveDate { in with_of()
1072 pub const fn succ(&self) -> NaiveDate { in succ()
1093 pub const fn succ_opt(&self) -> Option<NaiveDate> { in succ_opt()
1108 pub const fn pred(&self) -> NaiveDate { in pred()
1129 pub const fn pred_opt(&self) -> Option<NaiveDate> { in pred_opt()
1132 None => NaiveDate::from_ymd_opt(self.year() - 1, 12, 31), in pred_opt()
1150 /// assert_eq!(d.checked_add_signed(TimeDelta::days(-40)),
1153 /// assert_eq!(d.checked_add_signed(TimeDelta::days(-1_000_000_000)), None);
1157 pub const fn checked_add_signed(self, rhs: TimeDelta) -> Option<NaiveDate> { in checked_add_signed()
1179 /// assert_eq!(d.checked_sub_signed(TimeDelta::days(-40)),
1182 /// assert_eq!(d.checked_sub_signed(TimeDelta::days(-1_000_000_000)), None);
1186 pub const fn checked_sub_signed(self, rhs: TimeDelta) -> Option<NaiveDate> { in checked_sub_signed()
1187 let days = -rhs.num_days(); in checked_sub_signed()
1210 /// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2014, 1, 2)), TimeDelta::days(-1));
1217 pub const fn signed_duration_since(self, rhs: NaiveDate) -> TimeDelta { in signed_duration_since()
1224 TimeDelta::days((year1_div_400 as i64 - year2_div_400 as i64) * 146_097 + (cycle1 - cycle2)) in signed_duration_since()
1233 pub const fn years_since(&self, base: Self) -> Option<u32> { in years_since()
1234 let mut years = self.year() - base.year(); in years_since()
1238 years -= 1; in years_since()
1259 /// let fmt = StrftimeItems::new("%Y-%m-%d");
1261 /// assert_eq!(d.format_with_items(fmt.clone()).to_string(), "2015-09-05");
1262 /// assert_eq!(d.format("%Y-%m-%d").to_string(), "2015-09-05");
1270 /// # let fmt = StrftimeItems::new("%Y-%m-%d").clone();
1272 /// assert_eq!(format!("{}", d.format_with_items(fmt)), "2015-09-05");
1277 pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I> in format_with_items()
1305 /// assert_eq!(d.format("%Y-%m-%d").to_string(), "2015-09-05");
1306 /// assert_eq!(d.format("%A, %-d %B, %C%y").to_string(), "Saturday, 5 September, 2015");
1314 /// assert_eq!(format!("{}", d.format("%Y-%m-%d")), "2015-09-05");
1315 /// assert_eq!(format!("{}", d.format("%A, %-d %B, %C%y")), "Saturday, 5 September, 2015");
1320 pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>> { in format()
1325 #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
1332 ) -> DelayedFormat<I> in format_localized_with_items()
1344 #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
1351 ) -> DelayedFormat<StrftimeItems<'a>> { in format_localized()
1377 /// count -= 1;
1382 pub const fn iter_days(&self) -> NaiveDateDaysIterator { in iter_days()
1408 /// count -= 1;
1413 pub const fn iter_weeks(&self) -> NaiveDateWeeksIterator { in iter_weeks()
1420 pub const fn week(&self, start: Weekday) -> NaiveWeek { in week()
1435 pub const fn leap_year(&self) -> bool { in leap_year()
1441 const fn year(&self) -> i32 { in year()
1448 const fn ordinal(&self) -> u32 { in ordinal()
1454 const fn month(&self) -> u32 { in month()
1460 const fn day(&self) -> u32 { in day()
1466 const fn weekday(&self) -> Weekday { in weekday()
1472 pub(crate) const fn num_days_from_ce(&self) -> i32 { in num_days_from_ce()
1474 let mut year = self.year() - 1; in num_days_from_ce()
1477 let excess = 1 + (-year) / 400; in num_days_from_ce()
1479 ndays -= excess * 146_097; in num_days_from_ce()
1482 ndays += ((year * 1461) >> 2) - div_100 + (div_100 >> 2); in num_days_from_ce()
1493 NaiveDate { ymdf: ((MIN_YEAR - 1) << 13) | (366 << 4) | 0o07 /*FE*/ };
1500 /// Returns the year number in the [calendar date](#calendar-date).
1508 /// assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().year(), -308); // 309 BCE
1511 fn year(&self) -> i32 { in year()
1525 /// assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().month(), 3);
1528 fn month(&self) -> u32 { in month()
1542 /// assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().month0(), 2);
1545 fn month0(&self) -> u32 { in month0()
1546 self.month() - 1 in month0()
1559 /// assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().day(), 14);
1569 /// fn ndays_in_month(year: i32, month: u32) -> u32 {
1585 fn day(&self) -> u32 { in day()
1599 /// assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().day0(), 13);
1602 fn day0(&self) -> u32 { in day0()
1603 self.mdf().day() - 1 in day0()
1616 /// assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().ordinal(), 74);
1626 /// fn ndays_in_year(year: i32) -> u32 {
1641 fn ordinal(&self) -> u32 { in ordinal()
1655 /// assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().ordinal0(), 73);
1658 fn ordinal0(&self) -> u32 { in ordinal0()
1659 self.of().ordinal() - 1 in ordinal0()
1670 /// assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().weekday(), Weekday::Fri);
1673 fn weekday(&self) -> Weekday { in weekday()
1678 fn iso_week(&self) -> IsoWeek { in iso_week()
1696 /// assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_year(-308),
1697 /// Some(NaiveDate::from_ymd_opt(-308, 9, 8).unwrap()));
1708 fn with_year(&self, year: i32) -> Option<NaiveDate> { in with_year()
1736 fn with_month(&self, month: u32) -> Option<NaiveDate> { in with_month()
1758 fn with_month0(&self, month0: u32) -> Option<NaiveDate> { in with_month0()
1780 fn with_day(&self, day: u32) -> Option<NaiveDate> { in with_day()
1801 fn with_day0(&self, day0: u32) -> Option<NaiveDate> { in with_day0()
1829 fn with_ordinal(&self, ordinal: u32) -> Option<NaiveDate> { in with_ordinal()
1856 fn with_ordinal0(&self, ordinal0: u32) -> Option<NaiveDate> { in with_ordinal0()
1881 /// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::seconds(-86399), from_ymd(2014, 1, 1));
1883 /// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::days(-1), from_ymd(2013, 12, 31));
1894 fn add(self, rhs: TimeDelta) -> NaiveDate { in add()
1899 /// Add-assign of `TimeDelta` to `NaiveDate`.
1942 fn add(self, months: Months) -> Self::Output { in add()
1964 /// assert_eq!(from_ymd(2014, 1, 1) - Months::new(11), from_ymd(2013, 2, 1));
1965 /// assert_eq!(from_ymd(2014, 1, 1) - Months::new(12), from_ymd(2013, 1, 1));
1966 /// assert_eq!(from_ymd(2014, 1, 1) - Months::new(13), from_ymd(2012, 12, 1));
1971 fn sub(self, months: Months) -> Self::Output { in sub()
1972 self.checked_sub_months(months).expect("`NaiveDate - Months` out of range") in sub()
1985 fn add(self, days: Days) -> Self::Output { in add()
1999 fn sub(self, days: Days) -> Self::Output { in sub()
2000 self.checked_sub_days(days).expect("`NaiveDate - Days` out of range") in sub()
2022 /// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::zero(), from_ymd(2014, 1, 1));
2023 /// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::seconds(86399), from_ymd(2014, 1, 1));
2024 /// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::seconds(-86399), from_ymd(2014, 1, 1));
2025 /// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::days(1), from_ymd(2013, 12, 31));
2026 /// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::days(-1), from_ymd(2014, 1, 2));
2027 /// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::days(364), from_ymd(2013, 1, 2));
2028 /// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::days(365*4 + 1), from_ymd(2010, 1, 1));
2029 /// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::days(365*400 + 97), from_ymd(1614, 1, 1));
2037 fn sub(self, rhs: TimeDelta) -> NaiveDate { in sub()
2038 self.checked_sub_signed(rhs).expect("`NaiveDate - TimeDelta` overflowed") in sub()
2042 /// Subtract-assign `TimeDelta` from `NaiveDate`.
2075 /// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2014, 1, 1), TimeDelta::zero());
2076 /// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 12, 31), TimeDelta::days(1));
2077 /// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2014, 1, 2), TimeDelta::days(-1));
2078 /// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 9, 23), TimeDelta::days(100));
2079 /// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 1, 1), TimeDelta::days(365));
2080 /// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2010, 1, 1), TimeDelta::days(365*4 + 1));
2081 /// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(1614, 1, 1), TimeDelta::days(365*400 + 97));
2087 fn sub(self, rhs: NaiveDate) -> TimeDelta { in sub()
2093 fn from(naive_datetime: NaiveDateTime) -> Self { in from()
2107 fn next(&mut self) -> Option<Self::Item> { in next()
2115 fn size_hint(&self) -> (usize, Option<usize>) { in size_hint()
2124 fn next_back(&mut self) -> Option<Self::Item> { in next_back()
2143 fn next(&mut self) -> Option<Self::Item> { in next()
2149 fn size_hint(&self) -> (usize, Option<usize>) { in size_hint()
2158 fn next_back(&mut self) -> Option<Self::Item> { in next_back()
2168 /// [`d.format("%Y-%m-%d")`](crate::format::strftime).
2177 /// assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(2015, 9, 5).unwrap()), "2015-09-05");
2178 /// assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt( 0, 1, 1).unwrap()), "0000-01-01");
2179 /// assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(9999, 12, 31).unwrap()), "9999-12-31");
2186 /// assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt( -1, 1, 1).unwrap()), "-0001-01-01");
2187 /// assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(10000, 12, 31).unwrap()), "+10000-12-31");
2190 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
2199 // ISO 8601 requires the explicit sign for out-of-range years in fmt()
2203 f.write_char('-')?; in fmt()
2205 f.write_char('-')?; in fmt()
2211 /// [`d.format("%Y-%m-%d")`](crate::format::strftime).
2220 /// assert_eq!(format!("{}", NaiveDate::from_ymd_opt(2015, 9, 5).unwrap()), "2015-09-05");
2221 /// assert_eq!(format!("{}", NaiveDate::from_ymd_opt( 0, 1, 1).unwrap()), "0000-01-01");
2222 /// assert_eq!(format!("{}", NaiveDate::from_ymd_opt(9999, 12, 31).unwrap()), "9999-12-31");
2229 /// assert_eq!(format!("{}", NaiveDate::from_ymd_opt( -1, 1, 1).unwrap()), "-0001-01-01");
2230 /// assert_eq!(format!("{}", NaiveDate::from_ymd_opt(10000, 12, 31).unwrap()), "+10000-12-31");
2233 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
2239 /// [`%Y-%m-%d`](crate::format::strftime), as in `Debug` and `Display`.
2247 /// assert_eq!("2015-09-18".parse::<NaiveDate>(), Ok(d));
2250 /// assert_eq!("+12345-6-7".parse::<NaiveDate>(), Ok(d));
2257 fn from_str(s: &str) -> ParseResult<NaiveDate> { in from_str()
2261 Item::Literal("-"), in from_str()
2264 Item::Literal("-"), in from_str()
2286 fn default() -> Self { in default()
2291 const fn div_mod_floor(val: i32, div: i32) -> (i32, i32) { in div_mod_floor()
2295 #[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
2298 F: Fn(&NaiveDate) -> Result<String, E>, in test_encodable_json()
2303 Some(r#""2014-07-24""#.into()) in test_encodable_json()
2307 Some(r#""0000-01-01""#.into()) in test_encodable_json()
2310 to_string(&NaiveDate::from_ymd_opt(-1, 12, 31).unwrap()).ok(), in test_encodable_json()
2311 Some(r#""-0001-12-31""#.into()) in test_encodable_json()
2313 assert_eq!(to_string(&NaiveDate::MIN).ok(), Some(r#""-262143-01-01""#.into())); in test_encodable_json()
2314 assert_eq!(to_string(&NaiveDate::MAX).ok(), Some(r#""+262142-12-31""#.into())); in test_encodable_json()
2317 #[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
2320 F: Fn(&str) -> Result<NaiveDate, E>, in test_decodable_json()
2326 from_str(r#""2016-07-08""#).ok(), in test_decodable_json()
2329 assert_eq!(from_str(r#""2016-7-8""#).ok(), Some(NaiveDate::from_ymd_opt(2016, 7, 8).unwrap())); in test_decodable_json()
2330 assert_eq!(from_str(r#""+002016-07-08""#).ok(), NaiveDate::from_ymd_opt(2016, 7, 8)); in test_decodable_json()
2331 assert_eq!(from_str(r#""0000-01-01""#).ok(), Some(NaiveDate::from_ymd_opt(0, 1, 1).unwrap())); in test_decodable_json()
2332 assert_eq!(from_str(r#""0-1-1""#).ok(), Some(NaiveDate::from_ymd_opt(0, 1, 1).unwrap())); in test_decodable_json()
2334 from_str(r#""-0001-12-31""#).ok(), in test_decodable_json()
2335 Some(NaiveDate::from_ymd_opt(-1, 12, 31).unwrap()) in test_decodable_json()
2337 assert_eq!(from_str(r#""-262143-01-01""#).ok(), Some(NaiveDate::MIN)); in test_decodable_json()
2338 assert_eq!(from_str(r#""+262142-12-31""#).ok(), Some(NaiveDate::MAX)); in test_decodable_json()
2343 assert!(from_str(r#""2000-00-00""#).is_err()); in test_decodable_json()
2344 assert!(from_str(r#""2000-02-30""#).is_err()); in test_decodable_json()
2345 assert!(from_str(r#""2001-02-29""#).is_err()); in test_decodable_json()
2346 assert!(from_str(r#""2002-002-28""#).is_err()); in test_decodable_json()
2347 assert!(from_str(r#""yyyy-mm-dd""#).is_err()); in test_decodable_json()
2355 // pre-0.3.0 rustc-serialize format is now invalid in test_decodable_json()
2360 #[cfg(feature = "rustc-serialize")]
2366 fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { in encode()
2372 fn decode<D: Decoder>(d: &mut D) -> Result<NaiveDate, D::Error> { in decode()
2403 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> in serialize()
2412 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in serialize()
2426 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { in expecting()
2430 fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> in visit_str()
2439 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> in deserialize()
2465 // it is not self-describing. in test_serde_bincode()
2483 // we use a separate run-time test.
2552 Some(NaiveDate::from_ymd_opt(-28, 8, 3).unwrap()) in diff_months()
2567 // add clamping day, non-leap year in diff_months()
2614 // nine to five, seven-eleven in test_readme_doomsday()
2777 assert_eq!(from_ndays_from_ce(-365), Some(NaiveDate::from_ymd_opt(0, 1, 1).unwrap())); in test_date_from_num_days_from_ce()
2778 … assert_eq!(from_ndays_from_ce(-366), Some(NaiveDate::from_ymd_opt(-1, 12, 31).unwrap())); // 2 BCE in test_date_from_num_days_from_ce()
2780 for days in (-9999..10001).map(|x| x * 100) { in test_date_from_num_days_from_ce()
2785 assert_eq!(from_ndays_from_ce(NaiveDate::MIN.num_days_from_ce() - 1), None); in test_date_from_num_days_from_ce()
2894 assert_eq!(d.with_year(-400), Some(NaiveDate::from_ymd_opt(-400, 2, 29).unwrap())); in test_date_with_fields()
2895 assert_eq!(d.with_year(-100), None); in test_date_with_fields()
2934 for year in -9999..10001 { in test_date_num_days_from_ce()
2937 NaiveDate::from_ymd_opt(year - 1, 12, 31).unwrap().num_days_from_ce() + 1 in test_date_num_days_from_ce()
2968 assert_eq!(lhs.checked_sub_signed(-rhs), sum); in test_date_add()
2974 check((2014, 1, 1), TimeDelta::seconds(-86399), Some((2014, 1, 1))); in test_date_add()
2976 check((2014, 1, 1), TimeDelta::days(-1), Some((2013, 12, 31))); in test_date_add()
2981 check((-7, 1, 1), TimeDelta::days(365 * 12 + 3), Some((5, 1, 1))); in test_date_add()
2988 check((0, 1, 1), TimeDelta::days(MIN_DAYS_FROM_YEAR_0 as i64 - 1), None); in test_date_add()
2998 assert_eq!(rhs.signed_duration_since(lhs), -diff); in test_date_sub()
3027 check((-7, 1, 1), Days::new(365 * 12 + 3), Some((5, 1, 1))); in test_date_add_days()
3043 assert_eq!(lhs - diff, rhs); in test_date_sub_days()
3054 check((0, 1, 1), (MIN_YEAR, 1, 1), Days::new((-MIN_DAYS_FROM_YEAR_0).try_into().unwrap())); in test_date_sub_days()
3071 date -= TimeDelta::days(10); in test_date_subassignment()
3073 date -= TimeDelta::days(2); in test_date_subassignment()
3079 assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(2012, 3, 4).unwrap()), "2012-03-04"); in test_date_fmt()
3080 assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(0, 3, 4).unwrap()), "0000-03-04"); in test_date_fmt()
3081 assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(-307, 3, 4).unwrap()), "-0307-03-04"); in test_date_fmt()
3082 assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(12345, 3, 4).unwrap()), "+12345-03-04"); in test_date_fmt()
3084 assert_eq!(NaiveDate::from_ymd_opt(2012, 3, 4).unwrap().to_string(), "2012-03-04"); in test_date_fmt()
3085 assert_eq!(NaiveDate::from_ymd_opt(0, 3, 4).unwrap().to_string(), "0000-03-04"); in test_date_fmt()
3086 assert_eq!(NaiveDate::from_ymd_opt(-307, 3, 4).unwrap().to_string(), "-0307-03-04"); in test_date_fmt()
3087 assert_eq!(NaiveDate::from_ymd_opt(12345, 3, 4).unwrap().to_string(), "+12345-03-04"); in test_date_fmt()
3090 assert_eq!(format!("{:+30?}", NaiveDate::from_ymd_opt(1234, 5, 6).unwrap()), "1234-05-06"); in test_date_fmt()
3093 "+12345-06-07" in test_date_fmt()
3101 "-0000000123456-1-2", in test_date_from_str()
3102 " -123456 - 1 - 2 ", in test_date_from_str()
3103 "-12345-1-2", in test_date_from_str()
3104 "-1234-12-31", in test_date_from_str()
3105 "-7-6-5", in test_date_from_str()
3106 "350-2-28", in test_date_from_str()
3107 "360-02-29", in test_date_from_str()
3108 "0360-02-29", in test_date_from_str()
3109 "2015-2 -18", in test_date_from_str()
3110 "2015-02-18", in test_date_from_str()
3111 "+70-2-18", in test_date_from_str()
3112 "+70000-2-18", in test_date_from_str()
3113 "+00007-2-18", in test_date_from_str()
3154 "2014-01", // datetime missing data in test_date_from_str()
3155 "2014-01-00", // invalid day in test_date_from_str()
3156 "2014-11-32", // invalid day in test_date_from_str()
3157 "2014-13-01", // invalid month in test_date_from_str()
3158 "2014-13-57", // invalid month, day in test_date_from_str()
3159 "9999999-9-9", // invalid year (out of bounds) in test_date_from_str()
3171 NaiveDate::parse_from_str("2014-5-7T12:34:56+09:30", "%Y-%m-%dT%H:%M:%S%z"), in test_date_parse_from_str()
3175 NaiveDate::parse_from_str("2015-W06-1=2015-033", "%G-W%V-%u = %Y-%j"), in test_date_parse_from_str()
3183 assert!(NaiveDate::parse_from_str("2014-57", "%Y-%m-%d").is_err()); in test_date_parse_from_str()
3187 NaiveDate::parse_from_str("2020-01-0", "%Y-%W-%w").ok(), in test_date_parse_from_str()
3192 NaiveDate::parse_from_str("2019-01-0", "%Y-%W-%w").ok(), in test_date_parse_from_str()
3225 (Weekday::Mon, "Mon 2022-05-16", "Sun 2022-05-22"), in test_naiveweek()
3226 (Weekday::Tue, "Tue 2022-05-17", "Mon 2022-05-23"), in test_naiveweek()
3227 (Weekday::Wed, "Wed 2022-05-18", "Tue 2022-05-24"), in test_naiveweek()
3228 (Weekday::Thu, "Thu 2022-05-12", "Wed 2022-05-18"), in test_naiveweek()
3229 (Weekday::Fri, "Fri 2022-05-13", "Thu 2022-05-19"), in test_naiveweek()
3230 (Weekday::Sat, "Sat 2022-05-14", "Fri 2022-05-20"), in test_naiveweek()
3231 (Weekday::Sun, "Sun 2022-05-15", "Sat 2022-05-21"), in test_naiveweek()
3236 assert_eq!(Ok(week.first_day()), NaiveDate::parse_from_str(first_day, "%a %Y-%m-%d")); in test_naiveweek()
3237 assert_eq!(Ok(week.last_day()), NaiveDate::parse_from_str(last_day, "%a %Y-%m-%d")); in test_naiveweek()
3255 NaiveDate::parse_from_str("2020-01-0", "%Y-%W-%w").ok(), in test_weeks_from()
3259 NaiveDate::parse_from_str("2019-01-0", "%Y-%W-%w").ok(), in test_weeks_from()
3332 #[cfg(feature = "rkyv-validation")]
3335 let bytes = rkyv::to_bytes::<_, 4>(&date_min).unwrap(); in test_rkyv_validation()
3336 assert_eq!(rkyv::from_bytes::<NaiveDate>(&bytes).unwrap(), date_min); in test_rkyv_validation()
3339 let bytes = rkyv::to_bytes::<_, 4>(&date_max).unwrap(); in test_rkyv_validation()
3340 assert_eq!(rkyv::from_bytes::<NaiveDate>(&bytes).unwrap(), date_max); in test_rkyv_validation()
3343 // MAX_YEAR-12-31 minus 0000-01-01
3344 // = (MAX_YEAR-12-31 minus 0000-12-31) + (0000-12-31 - 0000-01-01)
3348 (MAX_YEAR + 1) * 365 + MAX_YEAR / 4 - MAX_YEAR / 100 + MAX_YEAR / 400;
3350 // MIN_YEAR-01-01 minus 0000-01-01
3353 MIN_YEAR * 365 + MIN_YEAR / 4 - MIN_YEAR / 100 + MIN_YEAR / 400;