[Datetime-SIG] Timeline arithmetic?
tim.peters at gmail.com
Mon Sep 7 23:44:39 CEST 2015
>> An aware datetime _is_ a <naive datetime,
>> tzinfo> pair, and there's a natural bijection between naive datetimes
>> and POSIX timestamps (across all instants both can represent).
> I don't understand this, and I suspect it's at the heart of our
> misunderstanding. I would say there are many possible bijections ....
"Natural" bijection. I gave you very simple Python code implementing
that bijection already. A naive datetime represents an instant in the
proleptic Gregorian calendar. So does a POSIX timestamp. In POSIX,
the relationship between a timestamp and calendar notation is defined
by the C expression ("/" is truncating integer division):
timestamp = tm_sec + tm_min*60 + tm_hour*3600 + tm_yday*86400 +
(tm_year-70)*31536000 + ((tm_year-69)/4)*86400 -
((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400
The natural bijection, between naive datetimes and POSIX timestamps,
is the bijection in which a naive datetime maps to/from the POSIX
timestamp such that
the naive datetime's calendar notation
is exactly equal to
the POSIX calendar notation
corresponding to that POSIX timestamp
as defined by the expression above.
Any other bijection is strained in comparison, hence "unnatural".
Natural doesn't necessarily mean unique (although it does in this
specific case - there is only one bijection satisfying the above);
"natural" is more related to Occam's Razor ;-)
>>> (POSIX timestamps are however embeddable in datetimes by using a fixed-offset tzinfo.)
>> Or use a naive datetime, for all practical purposes.
> Conceptually, sure, if you're willing to assume an implied
> fixed offset timezone. "For all practical purposes," no, because
> the _practical_ purpose of a model A tz-aware datetime is
> to always be able to easily and unambiguously ask it "how
> do you spell yourself in timezone X."
Guido wasn't talking about any of that, and neither was I. He was
talking about "embedding". That's passive with respect to thing being
embedded. Of course it's possible to "embed" a POSIX timestamp in a
naive datetime - for the purpose of being embedded, it's just a
frickin' integer ;-)
More information about the Datetime-SIG