time

Steve Holden steve at holdenweb.com
Tue Sep 28 05:02:35 CEST 2004


Bryan wrote:

> can someone explain to me why i get different values for the tm_yday and 
> tm_isdst values?
> 
>  >>> import rfc822
>  >>> rfc822.parsedate('Mar  1 01:03:59 2004')
> (2004, 3, 1, 1, 3, 59, 0, 0, 0)
> 
>  >>> import time
>  >>> time.strptime('Mar  1 01:03:59 2004', '%b %d %H:%M:%S %Y')
> (2004, 3, 1, 1, 3, 59, 0, 61, -1)
> 
The trivial answer is "because of differences in the modules". Your 
question is a bit like asking "Why is the sky today not the same color 
as it was yesterday?"

The docs for the time module explain that for strptime(): """The default 
values used to fill in any missing data is [sic] (1900, 1, 1, 0, 0, 0, 
0, 1, -1)""" and """Support for the %Z directive is based on the values 
contained in tzname and whether daylight is true. Because of this, it is 
platform-specific except for recognizing UTC and GMT which are always 
known (and are considered to be non-daylight savings timezones). """

Note that strptime used only to be present if your platform's C library 
provided it; though I can't say for sure that's changed I believe it 
has. No idea when, though.

The rfc822 docs for parsedate, on the other hand, specifically remark 
"""Note that fields 6, 7, and 8 of the result tuple are not usable.""".

So I suspect you are simply being disturbed by the lack of a consistency 
that was never intended to exist: you reads the docs and makes yer 
choice - ultimately, do what works in your application.

carefully-not-mentioning-hobgoblins-ly y'rs  - steve





More information about the Python-list mailing list