You've already forked parse_datetime
mirror of
https://github.com/uutils/parse_datetime.git
synced 2026-06-10 16:13:15 -07:00
Merge pull request #112 from jfinkels/fix-add-months-tests
Make tests of adding months more resilient
This commit is contained in:
@@ -319,10 +319,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_months() {
|
||||
use crate::parse_relative_time::add_months;
|
||||
|
||||
let now = Utc::now();
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "1 month").unwrap(),
|
||||
now.checked_add_months(Months::new(1)).unwrap()
|
||||
add_months(now, 1, false).unwrap(),
|
||||
);
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "this month").unwrap(),
|
||||
@@ -330,14 +332,14 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "1 month and 2 weeks").unwrap(),
|
||||
now.checked_add_months(Months::new(1))
|
||||
add_months(now, 1, false)
|
||||
.unwrap()
|
||||
.checked_add_days(Days::new(14))
|
||||
.unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "1 month and 2 weeks ago").unwrap(),
|
||||
now.checked_sub_months(Months::new(1))
|
||||
add_months(now, 1, true)
|
||||
.unwrap()
|
||||
.checked_sub_days(Days::new(14))
|
||||
.unwrap()
|
||||
@@ -348,7 +350,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "month").unwrap(),
|
||||
now.checked_add_months(Months::new(1)).unwrap()
|
||||
add_months(now, 1, false).unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -562,6 +564,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_duration_parsing() {
|
||||
use crate::parse_relative_time::add_months;
|
||||
|
||||
let now = Utc::now();
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "1 year").unwrap(),
|
||||
@@ -582,25 +586,25 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "1 month").unwrap(),
|
||||
now.checked_add_months(Months::new(1)).unwrap()
|
||||
add_months(now, 1, false).unwrap(),
|
||||
);
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "1 month and 2 weeks").unwrap(),
|
||||
now.checked_add_months(Months::new(1))
|
||||
add_months(now, 1, false)
|
||||
.unwrap()
|
||||
.checked_add_days(Days::new(14))
|
||||
.unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "1 month, 2 weeks").unwrap(),
|
||||
now.checked_add_months(Months::new(1))
|
||||
add_months(now, 1, false)
|
||||
.unwrap()
|
||||
.checked_add_days(Days::new(14))
|
||||
.unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "1 months 2 weeks").unwrap(),
|
||||
now.checked_add_months(Months::new(1))
|
||||
add_months(now, 1, false)
|
||||
.unwrap()
|
||||
.checked_add_days(Days::new(14))
|
||||
.unwrap()
|
||||
@@ -618,7 +622,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
parse_relative_time_at_date(now, "month").unwrap(),
|
||||
now.checked_add_months(Months::new(1)).unwrap()
|
||||
add_months(now, 1, false).unwrap(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user