Closed bjkeefe closed 1 year ago
Ah, the readme is outdated, <DstTzInfo 'Europe/Warsaw' WMT+1:24:00 STD>
is a pytz object. zoneinfo.ZoneInfo(key='America/New_York')
is the correct output for later versions.
OK, fixed that, thanks for the headsup!
Thanks! And, you're welcome: glad I could provide a tiny bit of help.
If it's not too much of a pain, could you also tell me:
tzlocal
?Again, TIA.
Daylight saving info is available in several different ways, depending on what you want. None of it is directly via tzlocal. Usually the best way is to get it from the time
module.
You won't see the debug output if you don't turn it on the first time you get the local zone, because subsequent times it will be cached.
First time:
>>> import logging
>>> logging.basicConfig(level="DEBUG")
>>> import tzlocal
>>> tzlocal.get_localzone()
DEBUG:root:/etc/timezone found, contents:
Europe/Warsaw
DEBUG:root:/etc/localtime found
DEBUG:root:2 found:
{'/etc/timezone': 'Europe/Warsaw', '/etc/localtime is a symlink to': 'Europe/Warsaw'}
zoneinfo.ZoneInfo(key='Europe/Warsaw')
Second time:
>>> tzlocal.get_localzone()
zoneinfo.ZoneInfo(key='Europe/Warsaw')
I just released 5.0, which is what I was effectively using when testing this, so if you still have problems, installing 5.0 might help, there's been a few changes.
Just upgraded to tzlocal-5.0, and that did the trick, as far as debugging goes. My output is slightly different from yours:
>>> import logging
>>> logging.basicConfig(level="DEBUG")
>>> import tzlocal
>>> tzlocal.get_localzone()
DEBUG:root:Looking up time zone info from registry
DEBUG:root:Found a TZ environment: America/New_York
DEBUG:root:Found a TZ environment: America/New_York
zoneinfo.ZoneInfo(key='America/New_York')
>>> tzlocal.get_localzone()
DEBUG:root:Found a TZ environment: America/New_York
zoneinfo.ZoneInfo(key='America/New_York')
As for Daylight Saving Time, I will take a look at your time
suggestion.
[added] For anyone else reading along, and wondering, both of these seem to do the trick:
>>> import time
>>> time.localtime().tm_isdst
1
>>> time.daylight
1
Thanks for your help, and for your timely responses. I would consider this issue closed, at least from my perspective.
Great!
Caveat: when I pip installed tzlocal a few days ago, this is what I got:
Perhaps all of what follows is due to my having v4.3, and not v5.something. If so, please advise. TIA!
Proceeding with the issue report ...
Following the readme, I ran the following:
The readme indicates I should have seen something like DST (or STD, for a different time of year) at the end of that.
Also note the difference in appearance of the result of the call to
tzlocal.get_localzone()
, compared to what is shown in the readme; e.g.,<DstTzInfo 'Europe/Warsaw' WMT+1:24:00 STD>
.Also note the absence of any debugging in the REPL session pasted above.