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

diff and duration calculates wrong days & hours (from v1.11.10 to v1.11.13) #2762

Open
rseiffert opened this issue Nov 1, 2024 · 0 comments

Comments

@rseiffert
Copy link

rseiffert commented Nov 1, 2024

Describe the bug
I have the following code fragment in a node.js based backend written in Typescript to calculate the difference between two DateTimes:

import dayjs from 'dayjs'
import duration from 'dayjs/plugin/duration'
import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'
...
dayjs.extend(duration)
dayjs.extend(utc)
dayjs.extend(timezone)
...
const date1 = dayjs().utc().local().tz('Europe/Berlin');
const date2 = dayjs('2025-03-13T00:00:00').utc().local().tz('Europe/Berlin')
const diff = dayjs.duration(date2.diff(date1))
console.info('date1', date1.format());
console.info('date2', date2.format());
console.info('diff:\n', diff);

This returns the wrong number of hours (console-output):

date1 2024-11-01T08:27:46+01:00
date2 2025-03-13T00:00:00+01:00
diff: 
l {
  '$d': {
    years: 0,
    months: 4,
    days: 9, // <== This is wrong
    hours: 23, // <= This is wrong
    minutes: 32,
    seconds: 13,
    milliseconds: 588
  },
  '$l': 'en',
  '$ms': 11374333588
}

This results in

  • 4 months, 9 days, 23 hours, 32 minutes
    (wrong numbers in bold)

Expected behavior
The correct result would be

  • 4 months, 11 days, 15 hours, 32 minutes

Additional information
Up to dayjs v.1.11.9 it works as expected. From v.1.11.10 to 1.11.13 it does not calculate correctly.

Information

  • Day.js Version v1.11.10 - v1.11.13
  • OS: macOS 15.1
  • Browser n/a (node.js v23.0.0)
  • Time zone: GMT+1 (CET)
@rseiffert rseiffert changed the title diff and duration calculate wrong days & hours diff and duration calculate wrong days & hours (from v1.11.10 to v1.11.13) Nov 1, 2024
@rseiffert rseiffert changed the title diff and duration calculate wrong days & hours (from v1.11.10 to v1.11.13) diff and duration calculates wrong days & hours (from v1.11.10 to v1.11.13) Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant