mavo
mavo copied to clipboard
`duration` should do better constraining
Issue raised in: https://github.com/mavoweb/mavo/issues/925#issuecomment-1272369432
Background: Right now, duration(ms: number, terms?: number | string)
only support either a given single unit (e.g. duration(3600*1000, "hour")
) or maximum number of units to output (those will be applied from maximum possible unit to smallest, e.g. terms=3
could result in a months, b days, c seconds
).
Problem: Users need better constraining, e.g. "need minimum unit as hours" or "start with hours and go up to 2 units higher"
Options:
- Provide
minUnit
andmaxUnit
(minUnit <= maxUnit
will be expected) - Provide only
minUnit
, and letterms
definemaxUnit
- Allow entering all possible units (e.g.
duration(T, "days", "hours")
)
I personally think given the current API, the second option is the most natural. When maxUnit
or multiple units are given, terms
become obsolete and design gets more complex.
Let's try to collect some use cases for this and see how the different syntax options compare. I'll try to remember some of mine.
I will add as I think and remember of more, but now I remember that initial instinct was something like duration(D, "hours", 2)
to have hours and minutes (it is like saying show me hours but with 2 precision). So that would be specifying maxUnit
and terms
.
That seems very confusing. Is it hours and minutes or hours and days? Whereas something like duration(D, from: 'minutes', to: 'hours')
seems clearer.
not even clear you need from: and to: . It might be nice if duration(D, "days", "minutes") and duration(D, "minutes", "days") both worked the same.
I'd argue it's not clear what duration(D, "days", "minutes")
means without documentation.