Closed flokli closed 5 years ago
It would be useful, no doubt. However, the current implementation (inheritance from the timedelta
class) prevent it from being trivial. And, furthermore, if you have an interval with 1 month, how many seconds is it (total_seconds()
method)? The fact is you can't know for certain.
So, for now, I won't integrate it in a near future but I will keep this in mind :-)
Sure, I totally agree its not trivial. But great to hear you'll keep this in mind :+1:
Closing this since it's now supported.
Currently, intervals are broken down into microseconds, seconds and days in Pendulum.
However, this might be not precise enough if you calculate with months. Adding months to a
Pendulum
instance is already supported byadd(months=n)
(with precise calculations), so we should be able to store months inInterval
instances too (and calculate with them).This would also allow a loss-free representation of the ISO8601 duration format in a
Duration
instance, and conversions from and to it ;-)Of course, there might be some corner cases that need to be considered - like what happens when 1 month is compared with 30 days.
I'd suggest to peek at the PostgreSQL
interval
implementation (with added microseconds):