Skip to content

Commit

Permalink
Fix test_leap_second during DST transition
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker authored and djc committed May 15, 2023
1 parent 0367c76 commit 3bfb6ab
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/offset/local/mod.rs
Expand Up @@ -246,18 +246,24 @@ mod tests {
// issue #123
let today = Utc::now().date_naive();

let dt = today.and_hms_milli_opt(1, 2, 59, 1000).unwrap();
let timestr = dt.time().to_string();
// the OS API may or may not support the leap second,
// but there are only two sensible options.
assert!(timestr == "01:02:60" || timestr == "01:03:00", "unexpected timestr {:?}", timestr);

let dt = today.and_hms_milli_opt(1, 2, 3, 1234).unwrap();
let timestr = dt.time().to_string();
assert!(
timestr == "01:02:03.234" || timestr == "01:02:04.234",
"unexpected timestr {:?}",
timestr
);
if let Some(dt) = today.and_hms_milli_opt(15, 2, 59, 1000) {
let timestr = dt.time().to_string();
// the OS API may or may not support the leap second,
// but there are only two sensible options.
assert!(
timestr == "15:02:60" || timestr == "15:03:00",
"unexpected timestr {:?}",
timestr
);
}

if let Some(dt) = today.and_hms_milli_opt(15, 2, 3, 1234) {
let timestr = dt.time().to_string();
assert!(
timestr == "15:02:03.234" || timestr == "15:02:04.234",
"unexpected timestr {:?}",
timestr
);
}
}
}

0 comments on commit 3bfb6ab

Please sign in to comment.