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

Unexpected behavior zonedTimeToUtc #243

Open
willwillems opened this issue Jul 7, 2023 · 1 comment
Open

Unexpected behavior zonedTimeToUtc #243

willwillems opened this issue Jul 7, 2023 · 1 comment

Comments

@willwillems
Copy link

I am in UTC + 3. I am running the following code:

zonedTimeToUtc(new Date(), Intl.DateTimeFormat().resolvedOptions().timeZone)

Where the second argument is correctly providing my timezone.

What am I expecting here: "Given a date and any time zone, returns a Date with the equivalent UTC time." I am expecting to see a Date object with a value that represents my current time (for example "14:47") in UTC, I would effectively see an offset of 3 hours as the result. Instead I'm getting back: the exact same timestamp.

However. When I run:

zonedTimeToUtc(new Date())

The result is what I would expect above.

The fact that this function works without a second argument is not documented in the readme or anywhere else I could find.

@mikomonday
Copy link

Similar to your initial code I had been extracting the timezone of the date fed into it thinking why it was necessary in the first place.

Ironically the function is typed to require this second value as well, I'm passing null as a second parameter just so TS isn't complaining which really doesn't make sense.

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

2 participants