From d75338a51b4059fdab2e84e289f928e5e6396c5e Mon Sep 17 00:00:00 2001 From: ysthakur <45539777+ysthakur@users.noreply.github.com> Date: Tue, 27 Aug 2024 19:02:08 -0400 Subject: [PATCH] Make tests for months without 30 days and leap years --- src/parse_relative_time.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/parse_relative_time.rs b/src/parse_relative_time.rs index 62f3d1c..96b9c34 100644 --- a/src/parse_relative_time.rs +++ b/src/parse_relative_time.rs @@ -672,6 +672,32 @@ mod tests { ); } + #[test] + fn test_parse_relative_time_at_date_month() { + // Use January because it has 31 days rather than 30 + let now = Utc.from_utc_datetime(&NaiveDateTime::new( + NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(), + NaiveTime::from_hms_opt(0, 0, 0).unwrap(), + )); + assert_eq!( + parse_relative_time_at_date(now, "1 month").unwrap(), + now.checked_add_months(Months::new(1)).unwrap() + ); + } + + #[test] + fn test_parse_relative_time_at_date_year() { + // Use 2024 because it's a leap year and has 366 days rather than 365 + let now = Utc.from_utc_datetime(&NaiveDateTime::new( + NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(), + NaiveTime::from_hms_opt(0, 0, 0).unwrap(), + )); + assert_eq!( + parse_relative_time_at_date(now, "1 year").unwrap(), + now.checked_add_months(Months::new(12)).unwrap() + ); + } + #[test] fn test_invalid_input_at_date_relative() { let now = Utc::now();