summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Misc/NEWS.d/next/Library/2018-09-13-21-04-23.bpo-34672.BYuKKS.rst2
-rw-r--r--Modules/timemodule.c23
2 files changed, 21 insertions, 4 deletions
diff --git a/Misc/NEWS.d/next/Library/2018-09-13-21-04-23.bpo-34672.BYuKKS.rst b/Misc/NEWS.d/next/Library/2018-09-13-21-04-23.bpo-34672.BYuKKS.rst
new file mode 100644
index 0000000000..59d106b600
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-09-13-21-04-23.bpo-34672.BYuKKS.rst
@@ -0,0 +1,2 @@
+Add a workaround, so the ``'Z'`` :func:`time.strftime` specifier on the musl
+C library can work in some cases.
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index dbe2fbaf07..9170505712 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -565,11 +565,26 @@ gettmarg(PyObject *args, struct tm *p, const char *format)
if (Py_TYPE(args) == &StructTimeType) {
PyObject *item;
item = PyTuple_GET_ITEM(args, 9);
- p->tm_zone = item == Py_None ? NULL : (char*)PyUnicode_AsUTF8(item);
+ if (item != Py_None) {
+ p->tm_zone = PyUnicode_AsUTF8(item);
+ if (p->tm_zone == NULL) {
+ return 0;
+ }
+ // Make an attempt to return the C library's own timezone strings to
+ // it. musl refuses to process a tm_zone field unless it produced
+ // it. See issue #34672.
+ if (tzname[0] && strcmp(p->tm_zone, tzname[0]) == 0) {
+ p->tm_zone = tzname[0];
+ } else if (tzname[1] && strcmp(p->tm_zone, tzname[1]) == 0) {
+ p->tm_zone = tzname[1];
+ }
+ }
item = PyTuple_GET_ITEM(args, 10);
- p->tm_gmtoff = item == Py_None ? 0 : PyLong_AsLong(item);
- if (PyErr_Occurred())
- return 0;
+ if (item != Py_None) {
+ p->tm_gmtoff = PyLong_AsLong(item);
+ if (PyErr_Occurred())
+ return 0;
+ }
}
#endif /* HAVE_STRUCT_TM_TM_ZONE */
return 1;