Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounding up .diff #344

Open
owen95t opened this issue Jul 27, 2022 · 2 comments
Open

Rounding up .diff #344

owen95t opened this issue Jul 27, 2022 · 2 comments

Comments

@owen95t
Copy link

owen95t commented Jul 27, 2022

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!

@spencermountain
Copy link
Owner

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

@owen95t
Copy link
Author

owen95t commented Aug 3, 2022

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants