Skip to content

Commit

Permalink
[Dates] Make test more robust against non-UTC timezones (#55829)
Browse files Browse the repository at this point in the history
`%M` is the format specifier for the minutes, not the month (which
should be `%m`), and it was used twice.

Also, on macOS `Libc.strptime` internally calls `mktime` which depends
on the local timezone. We now temporarily set `TZ=UTC` to avoid
depending on the local timezone.

Fix #55827.

(cherry picked from commit d6fa66f)
  • Loading branch information
giordano authored and KristofferC committed Sep 24, 2024
1 parent b0bf394 commit 1d51535
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion stdlib/Dates/test/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ end
end

@testset "issue #31524" begin
dt1 = Libc.strptime("%Y-%M-%dT%H:%M:%SZ", "2018-11-16T10:26:14Z")
# Ensure the result doesn't depend on local timezone, especially on macOS
# where an extra internal call to `mktime` is affected by timezone settings.
dt1 = withenv("TZ" => "UTC") do
Libc.strptime("%Y-%m-%dT%H:%M:%SZ", "2018-11-16T10:26:14Z")
end
dt2 = Libc.TmStruct(14, 30, 5, 10, 1, 99, 3, 40, 0)

time = Time(dt1)
Expand Down

0 comments on commit 1d51535

Please sign in to comment.