Skip to content

Commit d75338a

Browse files
committed
Make tests for months without 30 days and leap years
1 parent d4f67bb commit d75338a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/parse_relative_time.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,32 @@ mod tests {
672672
);
673673
}
674674

675+
#[test]
676+
fn test_parse_relative_time_at_date_month() {
677+
// Use January because it has 31 days rather than 30
678+
let now = Utc.from_utc_datetime(&NaiveDateTime::new(
679+
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
680+
NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
681+
));
682+
assert_eq!(
683+
parse_relative_time_at_date(now, "1 month").unwrap(),
684+
now.checked_add_months(Months::new(1)).unwrap()
685+
);
686+
}
687+
688+
#[test]
689+
fn test_parse_relative_time_at_date_year() {
690+
// Use 2024 because it's a leap year and has 366 days rather than 365
691+
let now = Utc.from_utc_datetime(&NaiveDateTime::new(
692+
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
693+
NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
694+
));
695+
assert_eq!(
696+
parse_relative_time_at_date(now, "1 year").unwrap(),
697+
now.checked_add_months(Months::new(12)).unwrap()
698+
);
699+
}
700+
675701
#[test]
676702
fn test_invalid_input_at_date_relative() {
677703
let now = Utc::now();

0 commit comments

Comments
 (0)