Skip to content

Commit c5caf18

Browse files
giordanoKristofferC
authored andcommitted
[Dates] Make test more robust against non-UTC timezones (#55829)
`%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)
1 parent 812cbc9 commit c5caf18

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

stdlib/Dates/test/types.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ end
257257
end
258258

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

263267
time = Time(dt1)

0 commit comments

Comments
 (0)