[Tutor] Daylight saving time issue

dman dsh8290@rit.edu
Tue, 6 Nov 2001 23:21:44 -0500


On Tue, Nov 06, 2001 at 05:40:53PM -0800, Titu Kim wrote:
| Hi,
|    I am trying to determine a given date is in dst or
| not. For instance, if i have month(mm), day(dd),
| year(yyyy) information plus the beginning (00:00:01)
| or ending (23:59:59) of this day, i would like to
| determine the given date/time is in daylight saving
| time. To make the situation complecated, i also have
| to consider the day when day light saving time occurs,
| which is in Oct and April each year. Any suggestion is
| very appreciated.

Create some date objects.

dst_start = day of year dst starts
dst_end = day of year dst ends

if dst_start < myday < dst_end :
    print "is DST"
else :
    print "not DST"


The real trick now is to define the date objects and have the
comparison ignore the year.  I know java has a Calendar class, but at the very
least a tuple might work.  

Let's see :

$ python
Python 1.5.2 (#0, Oct 20 2001, 16:30:45)  [GCC 2.95.4 20011006 (Debian prerelease)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> dst_end = (9 , 14)
>>> dst_start = (3 , 14)
>>> dst_start < dst_end
1
>>> today = (10 , 3)
>>> print dst_start < today < dst_end
0
>>>

(I made the months 0..11)
Honestly, though I don't know the dates for DST but this should give
an idea as to how to approach it.  If DST is during the winter, then
you would certainly want a function to tell you if the date is DST :

def is_dst( date ) :
    return date < dst_start or date > dst_end 


HTH,
-D