diff --git a/src/datetime/tests.rs b/src/datetime/tests.rs index 7105ca25ed..c327c6fffa 100644 --- a/src/datetime/tests.rs +++ b/src/datetime/tests.rs @@ -576,6 +576,31 @@ fn test_datetime_rfc2822() { assert!(DateTime::parse_from_rfc2822("Wed. 18 Feb 2015 23:16:09 +0000").is_err()); // *trailing* space causes failure assert!(DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +0000 ").is_err()); + + const RFC_2822_YEAR_MAX: i32 = 9999; + const RFC_2822_YEAR_MIN: i32 = 0; + + let dt = Utc.with_ymd_and_hms(RFC_2822_YEAR_MAX, 1, 2, 3, 4, 5).unwrap(); + assert_eq!(dt.to_rfc2822(), "Sat, 02 Jan 9999 03:04:05 +0000"); + + let dt = Utc.with_ymd_and_hms(RFC_2822_YEAR_MIN, 1, 2, 3, 4, 5).unwrap(); + assert_eq!(dt.to_rfc2822(), "Sun, 02 Jan 0000 03:04:05 +0000"); +} + +#[test] +#[should_panic] +#[cfg(feature = "alloc")] +#[allow(deprecated)] +fn test_rfc_2822_year_range_panic_high() { + let _ = Utc.with_ymd_and_hms(10000, 1, 2, 3, 4, 5).unwrap().to_rfc2822(); +} + +#[test] +#[should_panic] +#[cfg(feature = "alloc")] +#[allow(deprecated)] +fn test_rfc_2822_year_range_panic_low() { + let _ = Utc.with_ymd_and_hms(-1, 1, 2, 3, 4, 5).unwrap().to_rfc2822(); } #[test] @@ -665,6 +690,31 @@ fn test_datetime_rfc3339() { assert!(DateTime::parse_from_rfc3339(" 2015-02-18T23:59:60.234567+05:00").is_err()); assert!(DateTime::parse_from_rfc3339("2015- 02-18T23:59:60.234567+05:00").is_err()); assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567A+05:00").is_err()); + + const RFC_3339_YEAR_MAX: i32 = 9999; + const RFC_3339_YEAR_MIN: i32 = 0; + + let dt = Utc.with_ymd_and_hms(RFC_3339_YEAR_MAX, 1, 2, 3, 4, 5).unwrap(); + assert_eq!(dt.to_rfc3339(), "9999-01-02T03:04:05+00:00"); + + let dt = Utc.with_ymd_and_hms(RFC_3339_YEAR_MIN, 1, 2, 3, 4, 5).unwrap(); + assert_eq!(dt.to_rfc3339(), "0000-01-02T03:04:05+00:00"); +} + +#[test] +#[should_panic] +#[cfg(any(feature = "alloc", feature = "std"))] +#[allow(deprecated)] +fn test_rfc_3339_year_range_panic_high() { + let _ = Utc.with_ymd_and_hms(10000, 1, 2, 3, 4, 5).unwrap().to_rfc3339(); +} + +#[test] +#[should_panic] +#[cfg(any(feature = "alloc", feature = "std"))] +#[allow(deprecated)] +fn test_rfc_3339_year_range_panic_low() { + let _ = Utc.with_ymd_and_hms(-1, 1, 2, 3, 4, 5).unwrap().to_rfc3339(); } #[test]