spacetime icon indicating copy to clipboard operation
spacetime copied to clipboard

Rounding up .diff

Open owen95t opened this issue 3 years ago • 2 comments

I cant seem to find a way to do this, so I assume that currently it is impossible?

If so, it would be great to have this as a function.

Using this library to calculate penalty times by the hour, so it would be nice to have a round up function!

owen95t avatar Jul 27 '22 09:07 owen95t

hey @owen95t i'd love to know more about your idea -

we currently have .nearest, which could be coerced like this:

let rounded = s.nearest('hour')
if(rounded.isBefore(s)){
  rounded=rounded.add(1, 'hour')
}

lemme know cheers

spencermountain avatar Jul 27 '22 12:07 spencermountain

@spencermountain

One of the options that I love about dayjs is that their diff can actually return a float.

So instead of the logic above, i can simply do a

let rounded = Math.ceil(x.diff(y, 'hour', true)) / / true option allows for returning a float in dayjs

But I am using spacetime due to how spacetime can manipulate time, which i think is better than dayjs in the application I am working on.

Using nearest is a good option as well, just thought that it would also be nice to get a float back for more manipulation

owen95t avatar Aug 03 '22 09:08 owen95t