[Datetime-SIG] What's are the issues?

Chris Angelico rosuav at gmail.com
Wed Jul 29 03:43:56 CEST 2015


On Wed, Jul 29, 2015 at 11:28 AM, Chris Barker - NOAA Federal
<chris.barker at noaa.gov> wrote:
> So the question really is: should the datetime module provide what I've been
> calling "calendar operations" ?
>
> Yes, that would be very useful, but it's a heck of a lot more complicated
> than just redefine what a timedelta(days=1) means. And particularly with
> backward compatibility in mind, it definitely should not be done with that
> API.
>
> If people really are THAT prone to confusion that a day means 24 hours, then
> we should consider deprecating "days" as a valid unit for a timedelta.

What if the existing timedelta is left as-is, and a new calendardelta
type is introduced? Instead of folding everything down to a simple
microsecond count, it would retain the exact values it was given, so
calendardelta(days=1) != calendardelta(seconds=86400). When you add a
calendardelta to an aware datetime, it performs what you're describing
as calendar arithmetic, and it will be the most plausibly sane
behaviour for the exact unit used; so, for instance, adding
calendardelta(days=1) would never affect the hour/minute/second shown,
unless it would otherwise create an illegal time. Would that serve?

ChrisA


More information about the Datetime-SIG mailing list