diff options
author | Paul Monson <paulmon@users.noreply.github.com> | 2019-06-12 23:13:27 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-06-12 23:13:27 (GMT) |
commit | b4c7defe58695a6670a8fdeaef67a638bbb47e42 (patch) | |
tree | 6cc67accc1cc7190269bca65314e2ee3fe275d17 /Modules | |
parent | 95f61c8b1619e736bd5e29a0da0183234634b6e8 (diff) | |
download | cpython-b4c7defe58695a6670a8fdeaef67a638bbb47e42.zip cpython-b4c7defe58695a6670a8fdeaef67a638bbb47e42.tar.gz cpython-b4c7defe58695a6670a8fdeaef67a638bbb47e42.tar.bz2 |
bpo-36779: time.tzname returns empty string on Windows if default cod… (GH-13073)
Calling setlocale(LC_CTYPE, "") on a system where GetACP() returns CP_UTF8 results in empty strings in _tzname[].
This causes time.tzname to be an empty string.
I have reported the bug to the UCRT team and will follow up, but it will take some time get a fix into production.
In the meantime one possible workaround is to temporarily change the locale by calling setlocale(LC_CTYPE, "C") before calling _tzset and restore the current locale after if the GetACP() == CP_UTF8 or CP_UTF7
@zooba
https://bugs.python.org/issue36779
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/timemodule.c | 14 |
1 files changed, 14 insertions, 0 deletions
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; |