[Zope3-dev] Re: OT: pytz

Stuart Bishop stuart at stuartbishop.net
Thu Aug 3 03:09:07 EDT 2006


Ignas Mikalajunas wrote:
>> Thanks. I'd seen localize() in the README but all the examples have an
>> explicit is_dst passed which I didn't want. I didn't realize that
>> without it it would guess the right one (except during the 1h ambiguous
>> period).
>>
>> Florent
> 
> The is_dst parameter is more like "If it is ambiguous prefer DST",
> even when calling localize without passing the parameter it will not
> do any guessing as is_dst is set to False by default. If you want
> localize to warn you about ambiguous time you should pass is_dst=None
> which will raise an exception instead of assuming that you prefer non
> DST times in ambiguous cases,

I've been wondering if making pytz work like this was a correct decision. It
seems that people who know enough to care about DST transition periods
generally work in UTC anyway and perhaps the effort made to make pytz able
to correctly do date and time arithmetic in local time zones has much real
world benefit, and instead just confuses people who expect it to behave like
the Python Reference guide documents.

I've been toying with the idea of reworking it to work as the Python docs
describe, which will reintroduce off-by-one-hour errors for people doing
local timezone calculations in timezones with DST transition. I don't know
if it will be possible to support the original mode as well though.

(FWIW, Python's datetime instances do not store the is_dst flag found in
some other datetime libraries to solve this problem, as IIRC that single
extra bit would have bloated the pickles of datetime instances unacceptably.
pytz worked around this by stuffing the is_dst bit into the tzinfo, which
involves disgusting juggling and breaking the Python API somewhat. It is
somewhat ironic that the original use case for keeping the pickles minimal,
Zope, now seems to be standardizing on storing timestamps with timezone
information despite the fact it doubles (?) their storage size.)

-- 
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 191 bytes
Desc: OpenPGP digital signature
Url : http://mail.zope.org/pipermail/zope3-dev/attachments/20060803/aff4ec3e/signature.bin


More information about the Zope3-dev mailing list