• Home
  • Raw
  • Download

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

17 #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
34 #[cfg(any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"))]
35 use rkyv::{Archive, Deserialize, Serialize};
37 #[cfg(feature = "rustc-serialize")]
40 /// documented at re-export site
50 /// the general-purpose constructors are all via the methods on the
54 any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
58 #[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
74 /// This is a low-level method, intended for use cases such as deserializing a `DateTime` or
99 ) -> DateTime<Tz> { in from_naive_utc_and_offset()
110 pub fn from_utc(datetime: NaiveDateTime, offset: Tz::Offset) -> DateTime<Tz> { in from_utc()
128 pub fn from_local(datetime: NaiveDateTime, offset: Tz::Offset) -> DateTime<Tz> { in from_local()
129 let datetime_utc = datetime - offset.fix(); in from_local()
139 /// [`NaiveDate`] is a more well-defined type, and has more traits implemented on it,
151 pub fn date(&self) -> Date<Tz> { in date()
174 pub fn date_naive(&self) -> NaiveDate { in date_naive()
182 pub fn time(&self) -> NaiveTime { in time()
186 /// Returns the number of non-leap seconds since January 1, 1970 0:00:00 UTC
202 pub const fn timestamp(&self) -> i64 { in timestamp()
206 /// Returns the number of non-leap-milliseconds since January 1, 1970 UTC.
221 pub const fn timestamp_millis(&self) -> i64 { in timestamp_millis()
225 /// Returns the number of non-leap-microseconds since January 1, 1970 UTC.
240 pub const fn timestamp_micros(&self) -> i64 { in timestamp_micros()
244 /// Returns the number of non-leap-nanoseconds since January 1, 1970 UTC.
251 /// The dates that can be represented as nanoseconds are between 1677-09-21T00:12:43.145224192
252 /// and 2262-04-11T23:47:16.854775807.
257 pub const fn timestamp_nanos(&self) -> i64 { in timestamp_nanos()
261 /// Returns the number of non-leap-nanoseconds since January 1, 1970 UTC.
268 /// The dates that can be represented as nanoseconds are between 1677-09-21T00:12:43.145224192
269 /// and 2262-04-11T23:47:16.854775807.
283 /// assert_eq!(dt.timestamp_nanos_opt(), Some(-9_223_372_036_854_775_808));
296 pub const fn timestamp_nanos_opt(&self) -> Option<i64> { in timestamp_nanos_opt()
305 pub const fn timestamp_subsec_millis(&self) -> u32 { in timestamp_subsec_millis()
314 pub const fn timestamp_subsec_micros(&self) -> u32 { in timestamp_subsec_micros()
323 pub const fn timestamp_subsec_nanos(&self) -> u32 { in timestamp_subsec_nanos()
330 pub const fn offset(&self) -> &Tz::Offset { in offset()
337 pub fn timezone(&self) -> Tz { in timezone()
346 pub fn with_timezone<Tz2: TimeZone>(&self, tz: &Tz2) -> DateTime<Tz2> { in with_timezone()
354 pub fn fixed_offset(&self) -> DateTime<FixedOffset> { in fixed_offset()
362 pub const fn to_utc(&self) -> DateTime<Utc> { in to_utc()
373 pub fn checked_add_signed(self, rhs: TimeDelta) -> Option<DateTime<Tz>> { in checked_add_signed()
388 /// - The resulting date would be out of range.
389 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
392 pub fn checked_add_months(self, rhs: Months) -> Option<DateTime<Tz>> { in checked_add_months()
406 pub fn checked_sub_signed(self, rhs: TimeDelta) -> Option<DateTime<Tz>> { in checked_sub_signed()
421 /// - The resulting date would be out of range.
422 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
425 pub fn checked_sub_months(self, rhs: Months) -> Option<DateTime<Tz>> { in checked_sub_months()
437 /// - The resulting date would be out of range.
438 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
441 pub fn checked_add_days(self, days: Days) -> Option<Self> { in checked_add_days()
453 /// - The resulting date would be out of range.
454 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
457 pub fn checked_sub_days(self, days: Days) -> Option<Self> { in checked_sub_days()
471 ) -> TimeDelta { in signed_duration_since()
478 pub const fn naive_utc(&self) -> NaiveDateTime { in naive_utc()
491 pub fn naive_local(&self) -> NaiveDateTime { in naive_local()
504 pub(crate) fn overflowing_naive_local(&self) -> NaiveDateTime { in overflowing_naive_local()
514 pub fn years_since(&self, base: Self) -> Option<u32> { in years_since()
515 let mut years = self.year() - base.year(); in years_since()
519 years -= match earlier_time { in years_since()
538 pub fn to_rfc2822(&self) -> String { in to_rfc2822()
545 /// Returns an RFC 3339 and ISO 8601 date and time string such as `1996-12-19T16:39:57-08:00`.
548 pub fn to_rfc3339(&self) -> String { in to_rfc3339()
571 /// "2018-01-26T18:30:09.453+00:00");
573 /// "2018-01-26T18:30:09.453Z");
575 /// "2018-01-26T18:30:09Z");
580 /// "2018-01-26T10:30:09+08:00");
584 pub fn to_rfc3339_opts(&self, secform: SecondsFormat, use_z: bool) -> String { in to_rfc3339_opts()
598 /// Makes a new [`DateTime<Utc>`] from the number of non-leap seconds
600 /// and the number of nanoseconds since the last whole non-leap second.
602 /// This is guaranteed to round-trip with regard to [`timestamp`](DateTime::timestamp) and
609 /// [leap second](NaiveTime#leap-second-handling), but only when `secs % 60 == 59`.
614 /// Returns `None` on out-of-range number of seconds and/or
624 /// assert_eq!(dt.to_string(), "2015-05-15 00:00:00 UTC");
629 pub const fn from_timestamp(secs: i64, nsecs: u32) -> Option<Self> { in from_timestamp()
636 /// Makes a new [`DateTime<Utc>`] from the number of non-leap milliseconds
639 …/// This is guaranteed to round-trip with regard to [`timestamp_millis`](DateTime::timestamp_milli…
646 …/// Returns `None` on out-of-range number of milliseconds, otherwise returns `Some(DateTime {...})…
655 /// assert_eq!(dt.to_string(), "2000-01-12 01:02:03.004 UTC");
660 pub const fn from_timestamp_millis(millis: i64) -> Option<Self> { in from_timestamp_millis()
664 /// The Unix Epoch, 1970-01-01 00:00:00 UTC.
669 fn default() -> Self { in default()
676 fn default() -> Self { in default()
682 fn default() -> Self { in default()
693 fn from(src: DateTime<Utc>) -> Self { in from()
704 fn from(src: DateTime<Utc>) -> Self { in from()
715 fn from(src: DateTime<FixedOffset>) -> Self { in from()
727 fn from(src: DateTime<FixedOffset>) -> Self { in from()
739 fn from(src: DateTime<Local>) -> Self { in from()
750 fn from(src: DateTime<Local>) -> Self { in from()
756 fn map_local<Tz: TimeZone, F>(dt: &DateTime<Tz>, mut f: F) -> Option<DateTime<Tz>> in map_local()
758 F: FnMut(NaiveDateTime) -> Option<NaiveDateTime>, in map_local()
766 /// Parses an RFC 2822 date-and-time string into a `DateTime<FixedOffset>` value.
777 /// - A 2-digit year is interpreted to be a year in 1950-2049.
778 /// - The standard allows comments and whitespace between many of the tokens. See [4.3] and
780 /// - Single letter 'military' time zone names are parsed as a `-0000` offset.
782 /// the meaning is now ambiguous, the standard says they should be be considered as `-0000`
783 /// unless there is out-of-band information confirming their meaning.
786 /// [4.3]: https://www.rfc-editor.org/rfc/rfc2822#section-4.3
787 /// [Appendix A.5]: https://www.rfc-editor.org/rfc/rfc2822#appendix-A.5
798 pub fn parse_from_rfc2822(s: &str) -> ParseResult<DateTime<FixedOffset>> { in parse_from_rfc2822()
805 /// Parses an RFC 3339 date-and-time string into a `DateTime<FixedOffset>` value.
808 /// also valid RFC 3339 date-and-time values) and returns a new [`DateTime`] with a
810 /// variety of shapes and sizes, `1996-12-19T16:39:57-08:00` is an example of the most commonly
814 /// values in a wide range of formats, only some of which represent actual date-and-time
818 pub fn parse_from_rfc3339(s: &str) -> ParseResult<DateTime<FixedOffset>> { in parse_from_rfc3339()
827 /// Parses a string from a user-specified format into a `DateTime<FixedOffset>` value.
831 /// for a version that does not require a timezone in the to-be-parsed str. The returned
846 pub fn parse_from_str(s: &str, fmt: &str) -> ParseResult<DateTime<FixedOffset>> { in parse_from_str()
852 /// Parses a string from a user-specified format into a `DateTime<FixedOffset>` value, and a
870 /// "2015-02-18 23:16:09 +0200 trailing text", "%Y-%m-%d %H:%M:%S %z").unwrap();
880 ) -> ParseResult<(DateTime<FixedOffset>, &'a str)> { in parse_and_remainder()
895 pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I> in format_with_items()
919 pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>> { in format()
924 #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
931 ) -> DelayedFormat<I> in format_localized_with_items()
951 #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
958 ) -> DelayedFormat<StrftimeItems<'a>> { in format_localized()
965 fn year(&self) -> i32 { in year()
969 fn month(&self) -> u32 { in month()
973 fn month0(&self) -> u32 { in month0()
977 fn day(&self) -> u32 { in day()
981 fn day0(&self) -> u32 { in day0()
985 fn ordinal(&self) -> u32 { in ordinal()
989 fn ordinal0(&self) -> u32 { in ordinal0()
993 fn weekday(&self) -> Weekday { in weekday()
997 fn iso_week(&self) -> IsoWeek { in iso_week()
1009 /// - The resulting date does not exist.
1010 /// - When the `NaiveDateTime` would be out of range.
1011 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1013 fn with_year(&self, year: i32) -> Option<DateTime<Tz>> { in with_year()
1024 /// - The resulting date does not exist.
1025 /// - The value for `month` is invalid.
1026 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1029 fn with_month(&self, month: u32) -> Option<DateTime<Tz>> { in with_month()
1040 /// - The resulting date does not exist.
1041 /// - The value for `month0` is invalid.
1042 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1045 fn with_month0(&self, month0: u32) -> Option<DateTime<Tz>> { in with_month0()
1056 /// - The resulting date does not exist.
1057 /// - The value for `day` is invalid.
1058 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1061 fn with_day(&self, day: u32) -> Option<DateTime<Tz>> { in with_day()
1072 /// - The resulting date does not exist.
1073 /// - The value for `day0` is invalid.
1074 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1077 fn with_day0(&self, day0: u32) -> Option<DateTime<Tz>> { in with_day0()
1088 /// - The resulting date does not exist.
1089 /// - The value for `ordinal` is invalid.
1090 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1093 fn with_ordinal(&self, ordinal: u32) -> Option<DateTime<Tz>> { in with_ordinal()
1104 /// - The resulting date does not exist.
1105 /// - The value for `ordinal0` is invalid.
1106 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1109 fn with_ordinal0(&self, ordinal0: u32) -> Option<DateTime<Tz>> { in with_ordinal0()
1116 fn hour(&self) -> u32 { in hour()
1120 fn minute(&self) -> u32 { in minute()
1124 fn second(&self) -> u32 { in second()
1128 fn nanosecond(&self) -> u32 { in nanosecond()
1139 /// - The value for `hour` is invalid.
1140 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1143 fn with_hour(&self, hour: u32) -> Option<DateTime<Tz>> { in with_hour()
1153 /// - The value for `minute` is invalid.
1154 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1157 fn with_minute(&self, min: u32) -> Option<DateTime<Tz>> { in with_minute()
1171 /// - The value for `second` is invalid.
1172 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1175 fn with_second(&self, sec: u32) -> Option<DateTime<Tz>> { in with_second()
1179 /// Makes a new `DateTime` with nanoseconds since the whole non-leap second changed.
1191 fn with_nanosecond(&self, nano: u32) -> Option<DateTime<Tz>> { in with_nanosecond()
1201 fn eq(&self, other: &DateTime<Tz2>) -> bool { in eq()
1219 /// assert_eq!(earlier.to_string(), "2015-05-15 01:00:00 -01:00");
1220 /// assert_eq!(later.to_string(), "2015-05-14 22:00:00 -05:00");
1224 fn partial_cmp(&self, other: &DateTime<Tz2>) -> Option<Ordering> { in partial_cmp()
1230 fn cmp(&self, other: &DateTime<Tz>) -> Ordering { in cmp()
1255 fn add(self, rhs: TimeDelta) -> DateTime<Tz> { in add()
1274 fn add(self, rhs: Duration) -> DateTime<Tz> { in add()
1281 /// Add-assign `chrono::Duration` to `DateTime`.
1301 /// Add-assign `std::time::Duration` to `DateTime`.
1329 fn add(mut self, rhs: FixedOffset) -> DateTime<Tz> { in add()
1344 /// - The resulting date would be out of range.
1345 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1352 fn add(self, rhs: Months) -> Self::Output { in add()
1373 fn sub(self, rhs: TimeDelta) -> DateTime<Tz> { in sub()
1374 self.checked_sub_signed(rhs).expect("`DateTime - TimeDelta` overflowed") in sub()
1392 fn sub(self, rhs: Duration) -> DateTime<Tz> { in sub()
1395 self.checked_sub_signed(rhs).expect("`DateTime - TimeDelta` overflowed") in sub()
1399 /// Subtract-assign `TimeDelta` from `DateTime`.
1415 self.datetime.checked_sub_signed(rhs).expect("`DateTime - TimeDelta` overflowed"); in sub_assign()
1421 /// Subtract-assign `std::time::Duration` from `DateTime`.
1436 *self -= rhs; in sub_assign()
1449 fn sub(mut self, rhs: FixedOffset) -> DateTime<Tz> { in sub()
1451 self.naive_utc().checked_sub_offset(rhs).expect("`DateTime - FixedOffset` overflowed"); in sub()
1464 /// - The resulting date would be out of range.
1465 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1472 fn sub(self, rhs: Months) -> Self::Output { in sub()
1473 self.checked_sub_months(rhs).expect("`DateTime - Months` out of range") in sub()
1481 fn sub(self, rhs: DateTime<Tz>) -> TimeDelta { in sub()
1490 fn sub(self, rhs: &DateTime<Tz>) -> TimeDelta { in sub()
1500 /// - The resulting date would be out of range.
1501 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1508 fn add(self, days: Days) -> Self::Output { in add()
1518 /// - The resulting date would be out of range.
1519 /// - The local time at the resulting date does not exist or is ambiguous, for example during a
1526 fn sub(self, days: Days) -> Self::Output { in sub()
1527 self.checked_sub_days(days).expect("`DateTime - Days` out of range") in sub()
1532 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
1538 // `fmt::Debug` is hand implemented for the `rkyv::Archive` variant of `DateTime` because
1544 // * https://github.com/rust-lang/rust/issues/26925
1545 // * https://github.com/rkyv/rkyv/issues/333
1547 #[cfg(feature = "rkyv-validation")]
1555 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
1567 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
1581 /// "2012-12-12T12:12:12Z".parse::<DateTime<Utc>>()?;
1582 /// "2012-12-12 12:12:12Z".parse::<DateTime<Utc>>()?;
1583 /// "2012-12-12 12:12:12+0000".parse::<DateTime<Utc>>()?;
1584 /// "2012-12-12 12:12:12+00:00".parse::<DateTime<Utc>>()?;
1590 fn from_str(s: &str) -> ParseResult<DateTime<Utc>> { in from_str()
1602 /// "2012-12-12T12:12:12Z".parse::<DateTime<Local>>()?;
1603 /// "2012-12-12 12:12:12Z".parse::<DateTime<Local>>()?;
1604 /// "2012-12-12 12:12:12+0000".parse::<DateTime<Local>>()?;
1605 /// "2012-12-12 12:12:12+00:00".parse::<DateTime<Local>>()?;
1612 fn from_str(s: &str) -> ParseResult<DateTime<Local>> { in from_str()
1619 fn from(t: SystemTime) -> DateTime<Utc> { in from()
1627 (-sec, 0) in from()
1629 (-sec - 1, 1_000_000_000 - nsec) in from()
1639 fn from(t: SystemTime) -> DateTime<Local> { in from()
1646 fn from(dt: DateTime<Tz>) -> SystemTime { in from()
1651 UNIX_EPOCH - Duration::new(-sec as u64, 0) + Duration::new(0, nsec) in from()
1664 fn from(date: js_sys::Date) -> DateTime<Utc> { in from()
1675 fn from(date: &js_sys::Date) -> DateTime<Utc> { in from()
1689 fn from(date: DateTime<Utc>) -> js_sys::Date { in from()
1703 fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<DateTime<Tz>> { in arbitrary()
1710 #[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
1713 FUtc: Fn(&DateTime<Utc>) -> Result<String, E>, in test_encodable_json()
1714 FFixed: Fn(&DateTime<FixedOffset>) -> Result<String, E>, in test_encodable_json()
1719 Some(r#""2014-07-24T12:34:06Z""#.into()) in test_encodable_json()
1727 Some(r#""2014-07-24T12:34:06+01:01""#.into()) in test_encodable_json()
1736 Some(r#""2014-07-24T12:34:06+01:01""#.into()) in test_encodable_json()
1740 #[cfg(all(test, feature = "clock", any(feature = "rustc-serialize", feature = "serde")))]
1746 FUtc: Fn(&str) -> Result<DateTime<Utc>, E>, in test_decodable_json()
1747 FFixed: Fn(&str) -> Result<DateTime<FixedOffset>, E>, in test_decodable_json()
1748 FLocal: Fn(&str) -> Result<DateTime<Local>, E>, in test_decodable_json()
1752 fn norm<Tz: TimeZone>(dt: &Option<DateTime<Tz>>) -> Option<(&DateTime<Tz>, &Tz::Offset)> { in test_decodable_json()
1757 norm(&utc_from_str(r#""2014-07-24T12:34:06Z""#).ok()), in test_decodable_json()
1761 norm(&utc_from_str(r#""2014-07-24T13:57:06+01:23""#).ok()), in test_decodable_json()
1766 norm(&fixed_from_str(r#""2014-07-24T12:34:06Z""#).ok()), in test_decodable_json()
1772 norm(&fixed_from_str(r#""2014-07-24T13:57:06+01:23""#).ok()), in test_decodable_json()
1784 local_from_str(r#""2014-07-24T12:34:06Z""#).expect("local should parse"), in test_decodable_json()
1788 local_from_str(r#""2014-07-24T13:57:06+01:23""#).expect("local should parse with offset"), in test_decodable_json()
1792 assert!(utc_from_str(r#""2014-07-32T12:34:06Z""#).is_err()); in test_decodable_json()
1793 assert!(fixed_from_str(r#""2014-07-32T12:34:06Z""#).is_err()); in test_decodable_json()
1796 #[cfg(all(test, feature = "clock", feature = "rustc-serialize"))]
1802 FUtc: Fn(&str) -> Result<rustc_serialize::TsSeconds<Utc>, E>, in test_decodable_json_timestamps()
1803 FFixed: Fn(&str) -> Result<rustc_serialize::TsSeconds<FixedOffset>, E>, in test_decodable_json_timestamps()
1804 FLocal: Fn(&str) -> Result<rustc_serialize::TsSeconds<Local>, E>, in test_decodable_json_timestamps()
1807 fn norm<Tz: TimeZone>(dt: &Option<DateTime<Tz>>) -> Option<(&DateTime<Tz>, &Tz::Offset)> { in test_decodable_json_timestamps()
1816 norm(&utc_from_str("-1").ok().map(DateTime::from)), in test_decodable_json_timestamps()
1827 norm(&fixed_from_str("-1").ok().map(DateTime::from)), in test_decodable_json_timestamps()
1838 *local_from_str("-1").expect("-1 timestamp should parse"), in test_decodable_json_timestamps()