date diff calc

Peter Hansen peter at engcorp.com
Tue Nov 30 14:03:56 EST 2004


Tim Peters wrote:
> [Peter Hansen]
>>I think Skip was intending that the format string be mandatory,
>>to avoid such ambiguity.  
> 
> It's still a bottomless pit -- ask Brett, who implemented the Python
> strptime <wink>.  

True, I did overlook timezones at the time.

On the other hand, that's because *my* use cases for "simple"
fromstring() behaviour are all involving local time.  When
I'm interested in non-local time, I would be happy having
to specify that behaviour in a more complex manner.

> OTOH, is that what people really want?  For all I know,
> rfc822.getdate() or rfc822.getdate_tz() are what's really wanted, or
> maybe some DWIM thing like Zope's date guessers.

To each his own, although I think there's a hope here that
for those who might need/want a really simple solution,
95% of people have this in mind (pseudo-code):

class datetime.date:
     def fromstring(format, string):
         ts = time.mktime(time.strptime(string, format))
         return datetime.date.fromtimestamp(ts)

The .fromtimestamp() methods already work only for local
time, and I haven't heard anyone complaining about that
either.  (Hmm... haven't been listening either though. :-)

-Peter



More information about the Python-list mailing list