diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-09-12 18:23:51 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-09-14 17:24:34 +0200 |
commit | df2aaeb88a885440b2e7bcf3c28c9709a8700cf0 (patch) | |
tree | 8525d62696d5c10c7f318a0e55aaf3684d68b20f /src/timetype.rs | |
parent | 99af8dfbc094ea1e8ef17ad6f5158a5b7ce727b4 (diff) |
Add tests to test addition of more fancy values to moment
Diffstat (limited to 'src/timetype.rs')
-rw-r--r-- | src/timetype.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/timetype.rs b/src/timetype.rs index 59d6e9c..fdc28ba 100644 --- a/src/timetype.rs +++ b/src/timetype.rs @@ -1873,6 +1873,46 @@ mod moment_plus_amount_tests { expected = NaiveDate::from_ymd(2062, 1, 1).and_hms(0, 0, 0); } + generate_test_moment_plus_amount! { + name = test_moment_plus_more_than_one_year; + base = NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0); + amount = TT::years(1) + TT::months(1); + expected = NaiveDate::from_ymd(2001, 2, 1).and_hms(0, 0, 0); + } + + generate_test_moment_plus_amount! { + name = test_moment_plus_more_than_one_month; + base = NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0); + + // As we calculate 1 month + 1 day first, we end up adding 31 days to the base + amount = TT::months(1) + TT::days(1); + + // and therefor this results in the date 2000-02-01 + // This is not that inuitive, of course. + expected = NaiveDate::from_ymd(2000, 2, 1).and_hms(0, 0, 0); + } + + generate_test_moment_plus_amount! { + name = test_moment_plus_more_than_one_day; + base = NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0); + amount = TT::days(1) + TT::hours(1); + expected = NaiveDate::from_ymd(2000, 1, 2).and_hms(1, 0, 0); + } + + generate_test_moment_plus_amount! { + name = test_moment_plus_more_than_one_hour; + base = NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0); + amount = TT::hours(1) + TT::minutes(1); + expected = NaiveDate::from_ymd(2000, 1, 1).and_hms(1, 1, 0); + } + + generate_test_moment_plus_amount! { + name = test_moment_plus_more_than_one_minute; + base = NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0); + amount = TT::minutes(1) + TT::seconds(1); + expected = NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 1, 1); + } + generate_test_moment_minus_amount! { name = test_moment_minus_nothing; base = NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0); |