why no time() + timedelta() ?

John Machin sjmachin at lexicon.net
Thu Jan 20 19:34:51 EST 2005


Tim Peters wrote:
> [josh]
> > Why can't timedelta arithmetic be done on time objects?
>
> Obviously, because it's not implemented <wink>.
>
> > (e.g. datetime.time(5)-datetime.timedelta(microseconds=3)
> >
> > Nonzero "days" of the timedelta could either be ignored, or
> > trigger an exception.
>
> And if the result is less than 0, or >= 24 hours, it could raise
> OverflowError, or wrap around mod 24*60*60*1000000 microseconds, and
> so on.  There are so many arbitrary endcases that no agreement could
> be reached on what they "should" do.  So it's not supported at all.
> In contrast, it was much easier to reach consensus on what datetime
> arithmetic should do, so that was supported.

Reminds me of the debate at the time whether "add months" functionality
should be provided. Disagreement, including someone who shall remain
nameless opining that Jan 31 + one month should return Mar 3 (or Mar 2
in a leap year). Not supported at all. Those of us who dabble in arcane
esoterica like payrolls, pensions, mortgages, insurance, and government
bloody regulations had a quick ROTFL and started typing: class
RealWorldDateFunctionality(datetime.date): ...




More information about the Python-list mailing list