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

fromZonedTime of an iso date with a time zone #293

Open
sungbin-kim98 opened this issue Aug 1, 2024 · 2 comments
Open

fromZonedTime of an iso date with a time zone #293

sungbin-kim98 opened this issue Aug 1, 2024 · 2 comments

Comments

@sungbin-kim98
Copy link

fromZonedTime("2023-09-15T12:34:56-10:00", "Pacific/Honolulu")

I expected 2023-09-15T22:34:56Z but get 2023-09-16T04:34:56Z

@ttante
Copy link

ttante commented Aug 20, 2024

I haven't been able to get fromZonedTime or toZonedTime working correctly with the recent release. Everything keeps getting coerced into my local time zone.

@sungbin-kim98
Copy link
Author

I am working around it by

const isoTimeZoneRegex = /[+-](\d{2}):(\d{2})|Z$/

const parseISODateTime: (dateTime: string, timeZone: string) => Date = (dateTime, timeZone) => {
    if (isoTimeZoneRegex.test(dateTime)) {
        return new Date(dateTime)
    }
    return fromZonedTime(dateTime, timeZone)
}

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