[Datetime-SIG] Calendar vs timespan calculations...
Chris Barker
chris.barker at noaa.gov
Fri Jul 31 01:18:18 CEST 2015
On Thu, Jul 30, 2015 at 3:24 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> By the way -- which __add__ actually does the implementation? datetime's
>> or timedelta's ?
>>
>
> class timedelta:
>
> def __add__(self, other):
> if isinstance(other, timedelta):
> # for CPython compatibility, we cannot use
> # our __class__ here, but need a real timedelta
> return timedelta(self._days + other._days,
> self._seconds + other._seconds,
> self._microseconds + other._microseconds)
> return NotImplemented
>
>
> timedelta only adds directly to other timedeltas; so datetime is doing the
> actual addition.
great, thanks -- so timedelta knows nothing of datetimes at all, it seems
-- nice!
And you are quite right -- what we need a datetime with a different __add__
(and a few others, I suppose)
And it could be pretty darn backward compatible -- it would behave exactly
the same for naive datetimes, and, I think, any time zone without a DST,
and even any timezone when the DST boundary isn't crossed.
I'm thinking its "as simple" as:
- convert to utc
- convert to a timedelta from year 1
- do the addition
- convert back to a utc datetime
- convert back to the tzinfo's timezone
Or is there more to it than that that I'm missing?
-Chris
>
> --
> ~Ethan~
> _______________________________________________
> Datetime-SIG mailing list
> Datetime-SIG at python.org
> https://mail.python.org/mailman/listinfo/datetime-sig
> The PSF Code of Conduct applies to this mailing list:
> https://www.python.org/psf/codeofconduct/
>
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150730/354454bd/attachment.html>
More information about the Datetime-SIG
mailing list