Skip to content

Commit

Permalink
Merge pull request #1 from esheppa/add-asign-ext
Browse files Browse the repository at this point in the history
make sure add/sub_assign_local tests cross a DST transition if relevant
  • Loading branch information
MrGunflame committed Jun 9, 2022
2 parents d1a19e6 + 94374cf commit 705c2c3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/datetime/tests.rs
Expand Up @@ -433,13 +433,16 @@ fn test_datetime_add_assign() {
#[test]
#[cfg(feature = "clock")]
fn test_datetime_add_assign_local() {
let naivedatetime = NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0);
let naivedatetime = NaiveDate::from_ymd(2022, 1, 1).and_hms(0, 0, 0);

let datetime = Local.from_utc_datetime(&naivedatetime);
let mut datetime_add = datetime;
let mut datetime_add = Local.from_utc_datetime(&naivedatetime);

datetime_add += Duration::seconds(60);
assert_eq!(datetime_add, datetime + Duration::seconds(60));
// ensure we cross a DST transition
for i in 1..=365 {
datetime_add += Duration::days(1);
assert_eq!(datetime_add, datetime + Duration::days(i))
}
}

#[test]
Expand Down Expand Up @@ -467,11 +470,14 @@ fn test_datetime_sub_assign() {
#[test]
#[cfg(feature = "clock")]
fn test_datetime_sub_assign_local() {
let naivedatetime = NaiveDate::from_ymd(2000, 1, 1).and_hms(12, 0, 0);
let naivedatetime = NaiveDate::from_ymd(2022, 1, 1).and_hms(0, 0, 0);

let datetime = Local.from_utc_datetime(&naivedatetime);
let mut datetime_sub = datetime;
let mut datetime_sub = Local.from_utc_datetime(&naivedatetime);

datetime_sub -= Duration::minutes(90);
assert_eq!(datetime_sub, datetime - Duration::minutes(90));
// ensure we cross a DST transition
for i in 1..=365 {
datetime_sub -= Duration::days(1);
assert_eq!(datetime_sub, datetime - Duration::days(i))
}
}

0 comments on commit 705c2c3

Please sign in to comment.