On 2022-04-16 19:35:51 +0200, Peter J. Holzer wrote: > Note that t + d - d is in general not equal to t. > > We can't cnange the semantics of datetime - datetime, so there must be a > function to compute the difference between to datetimes as a > timedeltacal. It could be a method on datetime (maybe t.sub(u) for t-u > like in Go) or a constructor which takes two datetime objects.
Just noticed this. Using a method or constructor instead of an operator
adjusting behaviour via additional parameters.
So for example a parameter "maxunit" could be used to restrict the units
used in the result:
Given:
>>> CET = zoneinfo.ZoneInfo('Europe/Vienna')
>>> t0 = datetime.datetime(2022, 3, 1, tzinfo=CET)
>>> t1 = datetime.datetime(2022, 4, 16, 20, tzinfo=CET)
we could get these results:
>>> timedeltacal(t0, t1, maxunit="month")
timedeltacal(months=1, days=15, seconds=72000)
>>> timedeltacal(t0, t1, maxunit="days")
timedeltacal(days=46, seconds=72000)
>>> timedeltacal(t0, t1, maxunit="seconds")
timedeltacal(seconds=4042800)
(note that 4042800 == 46 * 86400 + 19 * 3600)
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | [email protected] | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list
