[Datetime-SIG] Are there any "correct" implementations of tzinfo?

Random832 random832 at fastmail.com
Mon Sep 14 15:58:34 EDT 2015


On Mon, Sep 14, 2015, at 15:30, Tim Peters wrote:
> You're assuming much more than POSIX - and the ISO C standard -
> requirs.  My description was quite explicitly about how POSIX has done
> it all along.  tm_gmtoff and tm_zone are extensions to the standards,
> introduced (IIRC) by BSD.  Portable code (including Python's
> implementation) can't assume they're available.

No, but that doesn't mean it's not in fact true (what was under
discussion was "your own machine", not "a minimal POSIX
implementation"). And it doesn't mean it's not a best practice that
python can and should copy. I'm not talking about *using* it, I'm
talking about working the same way independently, so this has nothing to
do with assuming it's available.

> It was off the table because, for backward compatibility, we need to
> mess with the pickle format as little as possible.  It's vital that
> datetimes obtained from old pickles continue to work fine, and that
> pickles obtained from new datetime objects work fine when loaded by
> older Pythons unless they actually require the new fold=1 possibility.

I don't see how this would prevent that. Aware datetimes have a tzinfo
*right there* that can be asked for a value to populate utcoffset with
if there isn't a pickled one.

> > (No, I don't *care* how that's not how it's defined,
> 
> ?  How what is defined?:

Just trying, unsuccessfully apparently, to head off the "no, it's
defined as working the same as a naive datetime if the tzinfo values are
the same" argument that got brought up the *last* time I made this
claim.

> > it is *in fact* true for the UTC value that you will ever actually get
> > from converting the values to UTC *today*, and it's the only total
> > ordering that actually makes any sense)
> 
> Well, you lost me there.  In a post-495 world, conversion to UTC will
> work correctly in all cases.  It cannot today.;

It'll provide *a* value in all cases. The sort order today is equivalent
to using that value in all cases unless you've got a pathological tzinfo
specifically crafted to break it. I think that's an important enough
invariant to be worth keeping, since it is the only possible way to
provide a total order in the presence of interzone comparisons.



More information about the Python-list mailing list