Skip to content

Commit

Permalink
make sure add/sub_assign_local tests cross a DST transition if relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
esheppa authored and MrGunflame committed Jun 10, 2022
1 parent 5156e0b commit 1fbf37a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/datetime/tests.rs
Expand Up @@ -452,13 +452,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 @@ -486,11 +489,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 1fbf37a

Please sign in to comment.