Title: '%Z' strftime specifier never works with musl
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, benjamin.peterson, p-ganssle
Priority: normal Keywords: patch

Created on 2018-09-14 04:01 by benjamin.peterson, last changed 2018-09-14 23:47 by p-ganssle.

Pull Requests
URL Status Linked Edit
PR 9288 merged benjamin.peterson, 2018-09-14 04:06
PR 9312 merged benjamin.peterson, 2018-09-14 17:04
Messages (3)
msg325319 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2018-09-14 04:01
With the musl C library, one has failures like this:

FAIL: test_strptime (test.test_time.TimeTestCase)
Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.ware-alpine/build/Lib/test/", line 273, in test_strptime
    time.strptime(strf_output, format)
ValueError: time data '' does not match format '%Z'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.ware-alpine/build/Lib/test/", line 276, in test_strptime
    (format, strf_output))
AssertionError: conversion specifier '%Z' failed with '' input.

The root problem is that time.strptime('%Z', time.gmtime()) won't work—it returns an empty string—even though time.gmtime() will probably have a valid tm_zone field. This is because musl has a safety mechanism where it refuses to process a tm_zone entry unless it produced the string. (See

As a partial workaround, I propose we check whether an incoming time.struct_time instance has an tm_zone member equal to tzname[0] or tzname[1], and place one of those global strings into the C-level tm struct if they do match.
msg325357 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2018-09-14 16:09
New changeset 5633c4f342d957df2ef0d67b9bfb472a0d28a76b by Benjamin Peterson in branch 'master':
bpo-34672: Try to pass the C library's own timezone strings back to it. (GH-9288)
msg325368 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2018-09-14 17:39
New changeset b93062b7fbc965cd0d522f597ed51eb4e493dfc2 by Benjamin Peterson in branch 'master':
bpo-34672: Don't pass NULL to gmtime_r. (GH-9312)
Date User Action Args
2018-09-14 23:47:23p-gansslesetnosy: + belopolsky
2018-09-14 17:39:16benjamin.petersonsetmessages: + msg325368
2018-09-14 17:04:31benjamin.petersonsetpull_requests: + pull_request8738
2018-09-14 16:21:53p-gansslesetnosy: + p-ganssle
2018-09-14 16:09:08benjamin.petersonsetmessages: + msg325357
2018-09-14 04:06:29benjamin.petersonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8719
2018-09-14 04:01:29benjamin.petersoncreate