radar/distance_of_time_in_words

highest measure rounding mode

seansfkelley opened this issue · 3 comments

Right now, using highest_measures/highest_measure_only simply truncates smaller units:

distance_of_time_in_words(Date.today, Date.today + 13.days, highest_measure_only: true)
 => "1 week" 

Depending on the context, this can be quite misleading. (For my space-constrained use-case, "1 week 6 days" in the above example would be needlessly precise.)

Would you be open to an option that describes what to do with the currently-ignored duration?

distance_of_time_in_words(Date.today, Date.today + 13.days, highest_measure_only: true, highest_measure_rounding: :round)
 => "2 weeks"

distance_of_time_in_words(Date.today, Date.today + 13.days, highest_measure_only: true, highest_measure_rounding: :floor)
 => "1 week"

# note that this is only +8 days
distance_of_time_in_words(Date.today, Date.today + 8.days, highest_measure_only: true, highest_measure_rounding: :ceiling)
 => "2 weeks"

Certainly! Would it make more sense to extend the highest_measure_only option to true, false, round, floor, ceiling or deprecate it for highest_measure: with these 3 options?

Great! I like the idea of consolidating them. It would feel artificially constrained to only allow highest_measure_only to do this. Also, I was slightly confused why the two different options existed. How about something like...

highest_measure: true
# same as
highest_measure: 1
# same as
highest_measure: { remainder: :floor }
# same as
highest_measure: {}

...and then some other variants like...

highest_measure: 2
# same as
highest_measure: { count: 2, remainder: :floor }
# which then suggests calls like
highest_measure: { count: 2, remainder: :round }

My use-case would then be expressible as...

highest_measure: { remainder: :round }

I'm not particular about the count/remainder verbiage. Did you intend to say highest_measures (with an s) or were you suggesting the addition of a new highest_measure option?

Let's talk it out in the PR! Thanks.