This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: time.daylight incorrect behavior in linux glibc
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, amaury.forgeotdarc, belopolsky, dimonb, lemburg
Priority: normal Keywords:

Created on 2011-11-16 07:49 by dimonb, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
daylight.c dimonb, 2011-11-16 07:49
Messages (6)
msg147752 - (view) Author: Dmitry Balabanov (dimonb) Date: 2011-11-16 07:49
In Europe/Moscow timezone:
>> import time
>> time.daylight
1
>>> time.timezone
-10800

But if compile and run attached program result would be:
timezone: -14400, daylight: 0

Daylight is not applicable in Europe/Moscow timezone from this winter. But python detect daylight flag as differences between January and July localtime. 

Why not tzset()?
msg221874 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-29 18:22
Could one of our timezone gurus respond to this please.
msg221885 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-06-29 19:21
I think this is out-of-date.  On Mac OS X, I get

```
$ python3 -V
Python 3.4.1
$ TZ=Europe/Moscow python3 -c "import time; print(time.daylight)"
0
```

I'll check on Linux now ...
msg221886 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-06-29 19:33
Same result on a freshly compiled

Python 3.4.1 (default, Jun 29 2014, 15:26:46)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux

$ TZ=Europe/Moscow ~/Apps/bin/python3 -c "import time; print(time.daylight)"
0

I suspect that the problem was with OP's system timezone database.
msg221888 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-06-29 19:40
> But python detect daylight flag as differences between January and July localtime.

This is the best we can do because time.daylight is a constant and this does not work in locations like Moscow where daylight rules were adopted ~ 30 years ago and later abandoned.

If you need better timezone support - take a look at datetime.datetime.astimezone() method.
msg221889 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-06-29 19:51
I suspect there will be another period soon when time.daylight logic will break after Europe/Moscow goes back to winter time (hopefully for good).

There is no solution of this issue within constraints of the time module.  See issue9527 for how it was solved in datetime.
History
Date User Action Args
2022-04-11 14:57:23adminsetgithub: 57622
2014-06-29 19:51:50belopolskysetmessages: + msg221889
2014-06-29 19:40:24belopolskysetstatus: open -> closed
resolution: works for me
messages: + msg221888

stage: resolved
2014-06-29 19:33:31belopolskysetmessages: + msg221886
2014-06-29 19:21:20belopolskysetmessages: + msg221885
2014-06-29 18:22:13BreamoreBoysetversions: + Python 2.7, Python 3.4, Python 3.5
nosy: + BreamoreBoy

messages: + msg221874

components: + Library (Lib)
2011-12-24 19:00:07ezio.melottisetnosy: + amaury.forgeotdarc
2011-11-16 11:38:02pitrousetnosy: + lemburg, belopolsky
2011-11-16 07:49:24dimonbcreate