The TZ env variable in cygwin contains local timezone info
$ echo $TZ
America/New_York
The datetime module prints UTC if TZ is set
$ /usr/local/anaconda3/python
Python 3.10.9 | packaged by Anaconda, Inc. | (main, Mar 1 2023, 18:18:15) [MSC
v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> print(datetime.datetime.now())
2023-07-02 20:49:23.692920
>>> quit()
$
and local time when TZ is not set
$ TZ= /usr/local/anaconda3/python
Python 3.10.9 | packaged by Anaconda, Inc. | (main, Mar 1 2023, 18:18:15) [MSC
v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> print(datetime.datetime.now())
2023-07-02 15:53:31.520504
>>> quit()
$
The tzlocal module prints local time zone if TZ is not set
$ TZ= /usr/local/anaconda3/python
Python 3.10.9 | packaged by Anaconda, Inc. | (main, Mar 1 2023, 18:18:15) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tzlocal
>>> tzlocal.get_localzone().zone
'America/New_York'
>>> quit()
$
and throws error when TZ is set
$ /usr/local/anaconda3/python
Python 3.10.9 | packaged by Anaconda, Inc. | (main, Mar 1 2023, 18:18:15) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tzlocal
>>> tzlocal.get_localzone().zone
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\cygwin64\usr\local\anaconda3\lib\site-packages\tzlocal\win32.py", line 95, in get_localzone
utils.assert_tz_offset(_cache_tz)
File "C:\cygwin64\usr\local\anaconda3\lib\site-packages\tzlocal\utils.py", line 46, in assert_tz_offset
raise ValueError(msg)
ValueError: Timezone offset does not match system offset: -14400 != 3600. Please, check your config files.
>>> quit()
$
When $TZ is set, tzlocal module works as expected but datetime module does not work as expected.
When $TZ is not set, tzlocal module does not work as expected but datetime module works as expected.
My thinking is that both modules should work as expected when $TZ is set.
Is this a problem with the datetime module in cygwin?