Skip to content

bpo-36779: time.tzname returns empty string on Windows if default cod… #13073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ensure ``time.tzname`` is correct on Windows when the active code page is
set to CP_UTF7 or CP_UTF8.
14 changes: 14 additions & 0 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down