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

differenceInSeconds() returns -0 when comparing the same date with millisecond differences #2555

ashutoshrishi opened this issue Jul 22, 2021 · 1 comment


Copy link

@ashutoshrishi ashutoshrishi commented Jul 22, 2021

let d = new Date("2021-07-22T06:01:28.973Z")
let e = new Date("2021-07-22T06:01:28.976Z")

differenceInSeconds(d, e)
// -0

differenceInSeconds(d, d)
// 0

I have tested this with the latest version 2.22.1. There is an older issue and test to prevent the negative 0, so maybe this is a regression?

For the above 2 dates, the differenceInMilliseconds is -0.003 and Math.ceil(-0.003) is -0.

Copy link

@pabrodez pabrodez commented Jul 28, 2021

I wouldn't mind date-fns returning -0 in the differenceIn* functions, but, -0) === false : (

What about Number((diff).toString()) ? Returns 0 for -0

@tan75 tan75 linked a pull request that will close this issue Aug 2, 2021
kossnocorp added a commit that referenced this issue Sep 17, 2021

Added `roundingMethod` option to `differenceInHours`, `differenceInMinutes`, `differenceInQuarters`, `differenceInSeconds` and `differenceInWeeks` with `trunc` as the default method. 

Co-authored-by: Lucas Silva <>
Co-authored-by: Tetiana <>
Co-authored-by: Sasha Koss <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants