Re: [Hampshire] Is a given date DST?

Top Page
Author: Chris Smith
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Is a given date DST?

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x580a8100.hantslug.org.uk.23370': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Tue Aug 12 11:19:24 2008 BST
gpg: using DSA key 11BEF6408586B4B2
gpg: Can't check signature: No public key
Keith Edmunds wrote:
>
> I'm looking for a way to write a function (ideally in Python) that takes
> one parameter, a datetime, and returns a Boolean which is true if the
> passed datetime is during "daylight saving time" and is false otherwise.


Look at the pytz and datetime modules. I'm no Python guru, but the
following appears to do the job:

##################
#!/usr/bin/python

from datetime import datetime
import pytz

utc_date = datetime(2008, 04, 3, 10, 00, 00, tzinfo=pytz.utc)
local_date = utc_date.astimezone(pytz.timezone('Europe/London'))

if local_date.dst().seconds != 0:
    print "Date is DST"
###################


This assumes that the input dates are always in UTC. If the input dates
are local, or mixed, it will give accurate results except for datetimes
that fall within the few hours of the clocks changing.

Chris
--
Chris Smith <cjs94@???>