Since the start and end times of DST in a timezone can change every year, so how does python tell if dst is in effect or not?
Asked
Active
Viewed 589 times
0
-
As in, in the `datetime` module, or `pytz` or elsewhere? – roganjosh Jul 03 '18 at 17:49
-
Yes, the datetime module @roganjosh – Raghav Bhartia Jul 03 '18 at 17:51
-
At the very [top of the source code](https://github.com/python/cpython/blob/master/Lib/datetime.py) for the module it gives a comment on where the DST data comes from – roganjosh Jul 03 '18 at 17:53
2 Answers
0
Actually my old answer was wrong. In the python shell you can do:
>>> import time
>>>time.localtime()
here it will show a result
>>> _.tm_isdst
This question is actually a duplicate but the old post can be found here: Python daylight savings time

Monish
- 13
- 1
- 7
-
This isn't my interpretation of the question. You're getting the `time` module to report that figure to you - how does it decide which figure to report to you in the first place? – roganjosh Jul 03 '18 at 17:56
-
I think you're still missing the point of the question. There should be some data source that Python can use to determine this, I have shown it in my answer. – roganjosh Jul 03 '18 at 18:04
-
Well I already gave it as an answer. And you're talking about the `time` module not the `datetime` module. – roganjosh Jul 03 '18 at 18:06
-
So I'm pretty sure that Python uses the computer to import the time but I could be wrong. – Monish Jul 03 '18 at 18:10
-
I'm not sure what we're trying to discuss here. If you're suggesting that Python relies entirely on system time then that clearly isn't correct because you can work in datetimes in timezones other than where your computer is physically located. I also gave a link to the source code of the actual module which says _explicitely_ that it uses an external datasource for DST data – roganjosh Jul 03 '18 at 18:13
-
Oh ok I see now , thanks! Basically when trying to get the `datetime` module, you do not want it to be relying on the computer but you want it to relate to the external datasource. – Monish Jul 03 '18 at 18:15
-
That isn't really what I'm saying. I don't know how much data is available from the system for, say, specifically whether Hawaii uses DST at all or whether it's in DST if it does. Python uses a documented, external source for that. – roganjosh Jul 03 '18 at 18:17
0
At the very top of the CPython source code for the datetime
module, it gives the source of the data:
"""Concrete date/time and related types. See http://www.iana.org/time-zones/repository/tz-link.html for time zone and DST data sources. """
Presumably this may be variable over time.

roganjosh
- 12,594
- 4
- 29
- 46