Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_leap_second during DST transition #1064

Merged
merged 1 commit into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/offset/local/mod.rs
Original file line number Diff line number Diff line change
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
);
}
}
}