luxon
luxon copied to clipboard
Add `Duration.min()` and `Duration.max()`
Can you please add static methods min
and max
to the Duration
, analogous to the methods in DateTime
?
Hey @icambron,
If you are ok with adding these methods to the Duration class, can I be assigned this issue? I have made some changes regarding this and can raise a PR for it.
This definitely is not trivial. The problem is that durations by default use "casual" conversion rules, which can make it so this comparison would not be reflexive or transitive, depending on which unit you use for comparison. For example: 29 days > 4 weeks, using days 4 weeks == 1 month, using weeks 29 days < 1 month, using days
So, 29 days is both larger and smaller than 1 month, considering the above logic.
Also: 4 weeks == 1 month, using weeks; but 4 weeks < 1 month, using days (because 28 days < 30 days)
This gets even more complicated if you have multiple (even different) units on both sides. So really, the user needs to tell which unit to use for the comparison. And even then they might not get the result they want.
I get what you are saying. I think could be done after any resolution of #1514, right?
No, this is an inherent property of the casual conversion matrix that Durations use by default. You can read more about it in the documentation.