"zoning" a naive datetime object / daylight savings

A

Adam Monsen

Say I have the following datetime[1] object:

I happen to know this is a local time from the Netherlands[2], so I
assume the tzinfo (if it were present) should indicate Central European
Summer Time[3] ("Summer" indicates daylight savings).

How do I convert this date/time information to UTC?

Using pytz[4], it appears that I should be able to do the following:

But this object has unexpected timezone information, and converts to
UTC by losing 9 minutes instead of 2 hours!
datetime.datetime(2005, 8, 10, 15, 34, tzinfo=<UTC>)

What I would *expect* to see is this:
datetime.datetime(2005, 8, 10, 13, 43, tzinfo=<UTC>)

Any pointers?

I feel like pytz/python should be smart enough to know that since the
date/time is 15:43 on August 10th, 2005 in the Europe/Paris timezone
that daylight savings is in effect, and the equivalent UTC datetime
object should contain a time two hours prior. At least, that's what I
like to happen.

Also, anyone know if there is a more appropriate choice for timezone
than "Europe/Paris" for times in the Netherlands?

Thank you,
-Adam

References:
1. http://docs.python.org/lib/datetime-datetime.html
2. http://en.wikipedia.org/wiki/Netherlands
3. http://en.wikipedia.org/wiki/Central_European_Time
4. http://pytz.sf.net
 
A

Adam Monsen

Ok, I think I figured this out. Comments/criticisms welcome.

----------------------------------8<----------------------------------
import datetime, os, time
from pytz import UTC
old_tz = os.environ.get('TZ')
os.environ['TZ'] = 'Europe/Amsterdam'
time.tzset()
dutchDateParts = (2005, 8, 10, 17, 26, 0, 2, 222, -1)
timestamp = time.mktime(dutchDateParts)
if old_tz: os.environ['TZ'] = old_tz
else: del os.environ['TZ']
time.tzset()
print datetime.datetime.fromtimestamp(timestamp, UTC)
---------------------------------->8----------------------------------


The 9-integer time tuple could be fetched using the code posted here:
http://snipurl.com/hcvs
same URL, not snipped:
http://groups.google.com/group/comp.lang.python/msg/65d8f116dfd59dd1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top