Issue 2525: class USTimeZone in Doc/includes/tzinfo-examples.py is out of date (original) (raw)

Created on 2008-04-01 03:54 by gvanrossum, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (11)

msg64800 - (view)

Author: Guido van Rossum (gvanrossum) * (Python committer)

Date: 2008-04-01 03:54

The USTimeZone example class hasn't been updated for the new US DST rules that went into effect in 2007. For a description of the new rules, see:

http://wwp.greenwichmeantime.com/daylight-saving-time/usa/dst-2007.htm

msg64850 - (view)

Author: Daniel Diniz (ajaksu2) * (Python triager)

Date: 2008-04-02 12:23

This patch updates the behavior as per "The Energy Policy Act of 2005":

  Start: Second Sunday in March
      End: First Sunday in November
      Time: 2 am local time

msg64868 - (view)

Author: Guido van Rossum (gvanrossum) * (Python committer)

Date: 2008-04-02 18:07

Hi Daniel,

Can you change it so that the start and end values are chosen dynamically based on the year? I.e. if year < 2007 use the old values otherwise use the new ones. A tzinfo object is supposed to (within reason) handle historical times accurately.

msg64872 - (view)

Author: Daniel Diniz (ajaksu2) * (Python triager)

Date: 2008-04-02 19:30

That was a such silly mistake, sorry :)

Updated patch tries to keep the old behavior, but I just found out it's mostly wrong too (DST start and end days changed a bit in the last 80 years).

From http://aa.usno.navy.mil/faq/docs/daylight_time.php (quoted below), I believe the best correctness/simplicity compromise would be:

1966-1986: from the last Sunday in April to the last Sunday in October 1987-2006: from the first Sunday in April to the last Sunday in October 2007-: from the last Sunday in March to the second Sunday in November

Should I try it like that? Or would more attention to detail be better?

quote: "Although standard time in time zones was instituted in the U.S. and Canada by the railroads in 1883, it was not established in U.S. law until the Act of March 19, 1918, sometimes called the Standard Time Act. The act also established daylight saving time, a contentious idea then. Daylight saving time was repealed in 1919, but standard time in time zones remained in law. Daylight time became a local matter. It was re-established nationally early in World War II, and was continuously observed from 9 February 1942 to 30 September 1945. After the war its use varied among states and localities. The Uniform Time Act of 1966 provided standardization in the dates of beginning and end of daylight time in the U.S. but allowed for local exemptions from its observance. The act provided that daylight time begin on the last Sunday in April and end on the last Sunday in October, with the changeover to occur at 2 a.m. local time.

During the "energy crisis" years, Congress enacted earlier starting dates for daylight time. In 1974, daylight time began on 6 January and in 1975 it began on 23 February. After those two years the starting date reverted back to the last Sunday in April. In 1986, a law was passed that shifted the starting date of daylight time to the first Sunday in April, beginning in 1987. The ending date of daylight time was not subject to such changes, and remained the last Sunday in October. The Energy Policy Act of 2005 changed both the starting and ending dates. Beginning in 2007, daylight time starts on the second Sunday in March and ends on the first Sunday in November."

msg64873 - (view)

Author: Daniel Diniz (ajaksu2) * (Python triager)

Date: 2008-04-02 19:31

Er... 2007- : from the second Sunday in March to the first Sunday in November.

:/

msg64874 - (view)

Author: Guido van Rossum (gvanrossum) * (Python committer)

Date: 2008-04-02 19:50

I'd be okay with only covering 1987 and later. But it's probably good to have a table-based solution anway, to make it easy to handle future changes -- I'm sure 2007 is not the last year this is changing. :-)

msg65003 - (view)

Author: Daniel Diniz (ajaksu2) * (Python triager)

Date: 2008-04-05 19:37

New patch. I added the new rule and changed the old behavior to be wrong (a bit) less often. It may mess with code that depended on the previous wrong results. Given the (AFAIK) exemplificative nature of this file, this should not be a big problem.

I was going to add a complete table for US DSTs rules, but that is already available in pytz (http://sourceforge.net/projects/pytz/ ) and there are many special cases for different US states.

Changes: Added a four periods approach (the three in my last msg plus "before 1967" -> no DST). Added links to the Olson Database and pytz (which IMHO would be a great addition to the std-lib). Tried to explain the rules, but I think the resulting text is pretty bad. Corrected a UnboundLocalError bug in my previous patch.

msg65084 - (view)

Author: Guido van Rossum (gvanrossum) * (Python committer)

Date: 2008-04-07 18:02

Hm, can you use lowercase for the local variable names dststart and dstend? Otherwise looks good.

msg65091 - (view)

Author: Daniel Diniz (ajaksu2) * (Python triager)

Date: 2008-04-07 18:42

Changed the local dststart, dstend variables to lowercase, "dates" to "times" (in "find start and end times") and the diff was created from trunk/ this time (as opposed to trunk/Doc/includes/).

msg65092 - (view)

Author: Guido van Rossum (gvanrossum) * (Python committer)

Date: 2008-04-07 18:47

Thanks, looks good. Since this is assigned to Georg, can you check it in, Georg?

Should this be backported to 2.5 docs as well?

msg65093 - (view)

Author: Georg Brandl (georg.brandl) * (Python committer)

Date: 2008-04-07 18:53

Committed as r62214, r62215 (2.5).

History

Date

User

Action

Args

2022-04-11 14:56:32

admin

set

github: 46777

2008-04-07 18:53:43

georg.brandl

set

status: open -> closed
resolution: accepted
messages: +

2008-04-07 18:47:23

gvanrossum

set

messages: +

2008-04-07 18:42:17

ajaksu2

set

files: + tzinfo-examples4.patch
messages: +

2008-04-07 18:02:17

gvanrossum

set

messages: +

2008-04-05 19:37:36

ajaksu2

set

files: + tzinfo-examples3.patch
messages: +

2008-04-02 19:50:07

gvanrossum

set

messages: +

2008-04-02 19:31:28

ajaksu2

set

messages: +

2008-04-02 19:30:12

ajaksu2

set

files: + tzinfo-examples2.patch
messages: +

2008-04-02 19:11:33

ajaksu2

set

files: - tzinfo-examples.patch

2008-04-02 18:07:59

gvanrossum

set

messages: +

2008-04-02 12:23:43

ajaksu2

set

files: + tzinfo-examples.patch
keywords: + patch
messages: +
nosy: + ajaksu2

2008-04-01 03:54:15

gvanrossum

create