You've already forked parse_datetime
mirror of
https://github.com/uutils/parse_datetime.git
synced 2026-06-10 16:13:15 -07:00
Make tests for months without 30 days and leap years
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user