Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.4k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…epage is a Unicode codepage
paulmon commentedMay 22, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This workaround enables time.tzname to work on Windows ARM32. |
matrixise commentedMay 22, 2019
Hi@paulmon I have edited the PR because that was the wrong BPO issue. Also, I have added this PR to the right bpo issue and removed it from the other one. |
paulmon commentedMay 22, 2019
Thank you! |
zooba commentedMay 22, 2019
Definitely needs the tabs converted to spaces, and I wonder if there's a better (Windows-specific) way to get this value without changing the locale? If we're going to have an ifdef, we may as well use the proper APIs, provided the values come back the same (I have no idea what values to expect here). @pganssle may also have an opinion. Or perhaps not :) |
paulmon commentedMay 22, 2019
I'll try to get the timezone name without changing the locale. |
pganssle commentedMay 22, 2019
Regardless of the resolution, I think this needs a test. What is this supposed to return on Windows? What does it return with the workaround? I think you can definitely get the time zone and alt zone names without changing the locale. One way to get it is from the registry, which is how we do itin There may be a more convenient way as well. |
paulmon commentedMay 23, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This is the fix for a failing test. It's supposed to return 'UTC-08:00' and it returns an empty string. FAIL: test_strptime (test.datetimetester.TestSubclassDateTime_Fast) Traceback (most recent call last): |
pganssle commentedMay 23, 2019
This is very confusing to me.This is the relevant test, and it seems like what it's doing is creating three strings: You can see what it's testing by running this script: importtimefromdatetimeimportdatetimefortzseconds,tznamein ((0,'UTC'), (0,'GMT'), (-time.timezone,time.tzname[0])):print("-----")print(f"tzseconds:{tzseconds}; tzname:{tzname}")iftzseconds<0:sign='-'seconds=-tzsecondselse:sign='+'seconds=tzsecondshours,minutes=divmod(seconds//60,60)dtstr="{}{:02d}{:02d} {}".format(sign,hours,minutes,tzname)print(dtstr) On my system, this returns: I am not sure where |
paulmon commentedMay 23, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
On Windows IoT Core on my dev machine (Windows 10 Enterprise) |
paulmon commentedMay 23, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
UTC-0800 is my local time zone This returns I tracked this this down to a bug in tzset() that sets _tzname[0] and _tzname[1] to empty strings when the default ANSI code page is set to CP_UTF8, or CP_UTF7. For more on the default ANSI code page see , seeGetACP( ) The default ANSI code page on most Windows installs is not CP_UTF7, or CP_UTF8. On my dev machine for example it is 1252 (Code Page Identifiers). On Windows IoT Core the default ANSI code page is 65001 or CP_UTF8. So in line 2511 of datetimetester.py _time.tzname[0] is empty causing the test to fail. Another way to check what the default ANSI codepage on your system is to run this command |
paulmon commentedMay 23, 2019
I think it doesn't raise an exception because it's valid to use "" as parameter to a format string. |
pganssle commentedMay 23, 2019
This is what I expected, but I don't understand why the test was working in the first place, on Linux: >>>datetime.strptime("-0800 ",'%z %Z')...ValueError:timedata'-0800 'doesnotmatchformat'%z %Z'>>>datetime.strptime("-0800 Pacific Standard Time","%z %Z")...ValueError:timedata'-0800 Pacific Standard Time'doesnotmatchformat'%z %Z' Is allowing empty format specifiers a Windows-specific thing? @paulmon If the two commands above don't fail for you, what do they return? What is |
paulmon commentedMay 23, 2019
Closing and re-opening to force azure pipelines to run again. |
paulmon commentedMay 24, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There seems to be a connection between the value of time.tzname and the results of those two commands. Without the current GetTimeZoneInformation fix With the GetTimeZoneInformation fix |
paulmon commentedMay 29, 2019
zooba commentedJun 11, 2019
@paulmon I think this one deserves a NEWS item - could you add it? |
miss-islington commentedJun 12, 2019
@paulmon: Status check is done, and it's a success ✅ . |
miss-islington commentedJun 12, 2019
Thanks@paulmon for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
bedevere-bot commentedJun 12, 2019
GH-14032 is a backport of this pull request to the3.8 branch. |
GH-13073) (GH-14032)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@zoobahttps://bugs.python.org/issue36779(cherry picked from commitb4c7def)Co-authored-by: Paul Monson <paulmon@users.noreply.github.com>
miss-islington commentedJun 13, 2019
Thanks@paulmon for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
pythonGH-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@zoobahttps://bugs.python.org/issue36779(cherry picked from commitb4c7def)Co-authored-by: Paul Monson <paulmon@users.noreply.github.com>
bedevere-bot commentedJun 13, 2019
GH-14057 is a backport of this pull request to the3.7 branch. |
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@zoobahttps://bugs.python.org/issue36779(cherry picked from commitb4c7def)Co-authored-by: Paul Monson <paulmon@users.noreply.github.com>
pganssle commentedJun 16, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@paulmon Hey sorry I never followed up on this - this is belated, but for the record I agree with this change. Thank you for for doing this - particularly because I learned something new about how |
bedevere-bot commentedJun 17, 2019
|
vstinner commentedJun 17, 2019
I reported this bug as:https://bugs.python.org/issue37314 |
paulmon commentedJun 17, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It looks like a different commit caused this buildbot failure. The only file changed in this commit is timemodule.c, and the build failures are all in _iomodule.c |
vstinner commentedJun 17, 2019
Welcome to the exciting universe of buildbots! |
pythonGH-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@zoobahttps://bugs.python.org/issue36779
pythonGH-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@zoobahttps://bugs.python.org/issue36779
Uh oh!
There was an error while loading.Please reload this page.
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