[Datetime-SIG] Datetime arithmetic proposal

Felipe Ochoa felipe.nospam.ochoa at gmail.com
Wed Jul 29 02:15:04 CEST 2015


My viewpoint (specifically on point 1 from my other email):

1. We cannot break backwards-compatibility (This point has been beaten to
death)
2. There are valid use-cases for wanting datetimes with and without
timezone info, and for doing naive and aware math. All 3 legal combinations
of the two (excluding naive dt with aware deltas :-)) have valid use-cases
3. [new point] If I'm a new user looking in the library for a solution to
my problem, my use-case is likely to appear "obviously correct", and I'll
be shocked if Python doesn't support it
4. [new point] The non-trivial nature of all 3 possibilities makes it
advantageous to include in the standard library

With that said, my proposal would be to:

A. Keep the current mechanics as-is. `+` and `-` result in "naive" datetime
arithmetic
B. Implement `.get_offset_time(self, hours, minutes, seconds, ms)` and
`.compute_duration(self, other_dt)` methods for "aware arithmetic." (I.e.,
congruent to 'convert to UTC, increment, convert back')
C. Come up with a new name (or clearly define naive/aware arithmetic) to
disambiguate the two
D. Document these differences clearly


Downsides:
* clunkyness of doing aware arithmetic
* `aware_dt + delta` can result in a nonexistent or ambiguous time
* `aware_dt_1 - aware_dt_2` behaves differently depending on the underlying
timezones
* [ fill in the blank -- I'm sure I'm missing many more ]

-Felipe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150728/713a8baa/attachment.html>


More information about the Datetime-SIG mailing list