summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Misc/NEWS.d/next/Windows/2019-06-11-15-41-34.bpo-36779.0TMw6f.rst2
-rw-r--r--Modules/timemodule.c14
2 files changed, 16 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Windows/2019-06-11-15-41-34.bpo-36779.0TMw6f.rst b/Misc/NEWS.d/next/Windows/2019-06-11-15-41-34.bpo-36779.0TMw6f.rst
new file mode 100644
index 0000000..618cfca
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2019-06-11-15-41-34.bpo-36779.0TMw6f.rst
@@ -0,0 +1,2 @@
+Ensure ``time.tzname`` is correct on Windows when the active code page is
+set to CP_UTF7 or CP_UTF8.
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index f991f31..bdc93a2 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -1581,6 +1581,19 @@ init_timezone(PyObject *m)
PyModule_AddIntConstant(m, "altzone", _Py_timezone-3600);
#endif
PyModule_AddIntConstant(m, "daylight", _Py_daylight);
+#ifdef MS_WINDOWS
+ TIME_ZONE_INFORMATION tzinfo = {0};
+ GetTimeZoneInformation(&tzinfo);
+ otz0 = PyUnicode_FromWideChar(tzinfo.StandardName, -1);
+ if (otz0 == NULL) {
+ return -1;
+ }
+ otz1 = PyUnicode_FromWideChar(tzinfo.DaylightName, -1);
+ if (otz1 == NULL) {
+ Py_DECREF(otz0);
+ return -1;
+ }
+#else
otz0 = PyUnicode_DecodeLocale(_Py_tzname[0], "surrogateescape");
if (otz0 == NULL) {
return -1;
@@ -1590,6 +1603,7 @@ init_timezone(PyObject *m)
Py_DECREF(otz0);
return -1;
}
+#endif // MS_WINDOWS
PyObject *tzname_obj = Py_BuildValue("(NN)", otz0, otz1);
if (tzname_obj == NULL) {
return -1;