mavo icon indicating copy to clipboard operation
mavo copied to clipboard

`duration` should do better constraining

Open BarishNamazov opened this issue 2 years ago • 5 comments

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 and maxUnit (minUnit <= maxUnit will be expected)
  • Provide only minUnit, and let terms define maxUnit
  • 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.

BarishNamazov avatar Oct 08 '22 23:10 BarishNamazov

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.

LeaVerou avatar Oct 13 '22 17:10 LeaVerou

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.

BarishNamazov avatar Oct 14 '22 00:10 BarishNamazov

That seems very confusing. Is it hours and minutes or hours and days? Whereas something like duration(D, from: 'minutes', to: 'hours') seems clearer.

LeaVerou avatar Oct 14 '22 05:10 LeaVerou

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.

karger avatar Oct 16 '22 16:10 karger

I'd argue it's not clear what duration(D, "days", "minutes") means without documentation.

LeaVerou avatar Oct 16 '22 18:10 LeaVerou