@@ -1619,34 +1619,28 @@ init_timezone(PyObject *m)
16191619 And I'm lazy and hate C so nyer.
16201620 */
16211621#ifdef HAVE_DECL_TZNAME
1622- #ifdef MS_WINDOWS
1623- # include <locale.h>
1624- // https://bugs.python.org/issue36778
1625- // workaround bug in UCRT
1626- // strptime fails if the current locale is a Unicode locale
1627- int cp = GetACP ();
1628- char * save_locale = NULL ;
1629- if (cp == CP_UTF8 || cp == CP_UTF7 )
1630- {
1631- save_locale = setlocale (LC_CTYPE , NULL );
1632- setlocale (LC_CTYPE , "C" );
1633- }
1634- #endif
16351622 PyObject * otz0 , * otz1 ;
16361623 tzset ();
16371624 PyModule_AddIntConstant (m , "timezone" , _Py_timezone );
1638- #ifdef MS_WINDOWS
1639- if (cp == CP_UTF8 || cp == CP_UTF7 )
1640- {
1641- setlocale (LC_CTYPE , save_locale );
1642- }
1643- #endif
16441625#ifdef HAVE_ALTZONE
16451626 PyModule_AddIntConstant (m , "altzone" , altzone );
16461627#else
16471628 PyModule_AddIntConstant (m , "altzone" , _Py_timezone - 3600 );
16481629#endif
16491630 PyModule_AddIntConstant (m , "daylight" , _Py_daylight );
1631+ #ifdef MS_WINDOWS
1632+ TIME_ZONE_INFORMATION tzinfo = {0 };
1633+ GetTimeZoneInformation (& tzinfo );
1634+ otz0 = PyUnicode_FromWideChar (tzinfo .StandardName , -1 );
1635+ if (otz0 == NULL ) {
1636+ return -1 ;
1637+ }
1638+ otz1 = PyUnicode_FromWideChar (tzinfo .DaylightName , -1 );
1639+ if (otz1 == NULL ) {
1640+ Py_DECREF (otz0 );
1641+ return -1 ;
1642+ }
1643+ #else
16501644 otz0 = PyUnicode_DecodeLocale (_Py_tzname [0 ], "surrogateescape" );
16511645 if (otz0 == NULL ) {
16521646 return -1 ;
@@ -1656,6 +1650,7 @@ init_timezone(PyObject *m)
16561650 Py_DECREF (otz0 );
16571651 return -1 ;
16581652 }
1653+ #endif // MS_WINDOWS
16591654 PyObject * tzname_obj = Py_BuildValue ("(NN)" , otz0 , otz1 );
16601655 if (tzname_obj == NULL ) {
16611656 return -1 ;
0 commit comments