Re: converting a timezone-less datetime to seconds since the epoch

2010-04-07 Thread Floris Bruynooghe
On Apr 7, 9:57 am, Chris Withers wrote: > Chris Rebert wrote: > > To convert from struct_time in ***UTC*** > > to seconds since the epoch > > use calendar.timegm() > > ...and really, wtf is timegm doing in calendar rather than in time? ;-) You're not alone in finding this strange: http://bugs.pyt

Re: converting a timezone-less datetime to seconds since the epoch

2010-04-07 Thread Chris Withers
Hi Chris, Chris Rebert wrote: from calendar import timegm def timestamp(dttm): return timegm(dttm.utctimetuple()) #the *utc*timetuple change is just for extra consistency #it shouldn't actually make a difference here And problem solved. As for what the problem was: Paraphrasing the table

Re: converting a timezone-less datetime to seconds since the epoch

2010-03-18 Thread Chris Withers
Hey Chris, Chris Rebert wrote: def timestamp(dttm): return time.mktime(dttm.timetuple()) from calendar import timegm def timestamp(dttm): return timegm(dttm.utctimetuple()) #the *utc*timetuple change is just for extra consistency #it shouldn't actually make a difference here Ah, righ

Re: converting a timezone-less datetime to seconds since the epoch

2010-03-16 Thread Chris Rebert
On Tue, Mar 16, 2010 at 6:47 AM, Chris Withers wrote: > Hi All, > > We have a bunch of datetime objects that have tzinfo=None. > We want to turn them into float timestamps in seconds since the epoch. > > Here's the first attempt: > > import time > from datetime import datetime > from unittest impo