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

incorrect difference in hours while working with DST date #287

Open
mukhrr opened this issue May 22, 2024 · 0 comments
Open

incorrect difference in hours while working with DST date #287

mukhrr opened this issue May 22, 2024 · 0 comments

Comments

@mukhrr
Copy link

mukhrr commented May 22, 2024

The problem
💻 Code demonstrating the problem

import { fromZonedTime, toZonedTime } from "date-fns-tz"
import { add, differenceInHours, parseISO } from "date-fns"

const dstOffset = (value: any) => {
  const zone = "America/Chicago"

  const start = toZonedTime(fromZonedTime(parseISO(value), zone), zone)
  const end = toZonedTime(fromZonedTime(add(parseISO(value), { days: 1 }), zone), zone)

  const diff = differenceInHours(end, start)

  return diff
}

console.log(dstOffset("2024-03-10"))

//=> Expected output
// 23

//=> Problematic output
// 24

🙁 Actual behavior
Output of dstOffset with the above arguments is 24 hours

🙂 Expected behavior
The output of dstOffset with the above arguments should be 23 hours because 2024-03-10 is DST date with America/Chicago (-4) timezone

Debug information
date-fns version: ^3.6.0
date-fns-tz version: ^3.1.3
Browser/Node.js version: node v20.12.2
Your timezone: GMT +5 Tashkent
Your current time: 12:22 pm

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