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

RangeError: Invalid time zone specified: error caused by usage of formatInTimeZone function for some folks #264

Open
wordswithchung opened this issue Dec 27, 2023 · 7 comments

Comments

@wordswithchung
Copy link

Our DataDog was reporting this error -- RangeError: Invalid time zone specified: -- for about 15 different users internationally. The time zones it would list are definitely not invalid. Some included:

  • America/New_York
  • Asia/Manila
  • Europe/London

The stack trace pointed to getTimeZoneOffSet:

RangeError: Invalid time zone specified: Asia/Manila
  at getTimeZoneOffset 
  at Object.X
  at <anonymous>
  at Array.reduce 
  at format_format
  at formatInTimeZone

It's failing at tzParseTimezone, particularly where it checks isValidTimezoneIANAString(timezoneString). That function relies on the existence of Intl.DateTimeFormat to determine if a time zone is valid or not. Which doesn't work for everyone.

var validIANATimezoneCache = {}
function isValidTimezoneIANAString(timeZoneString) {
  if (validIANATimezoneCache[timeZoneString]) return true
  try {
    new Intl.DateTimeFormat(undefined, { timeZone: timeZoneString })
    validIANATimezoneCache[timeZoneString] = true
    return true
  } catch (error) {
    return false
  }
}

Would it be possible to use a different way to check in isValidTimezoneIANAString? Thank you! 🙇

@wordswithchung wordswithchung changed the title RangeError: Invalid time zone specified: error caused by usage of formatInTimeZone function for some folks RangeError: Invalid time zone specified: error caused by usage of formatInTimeZone function for some folks Dec 27, 2023
@sathishdevelops
Copy link

Still facing the same issue for this Timezone: Asia/Kolkata, Any update or workaround for this?

@CaptainJeff
Copy link

Same issue happening for me in react native

@tao-qian
Copy link

tao-qian commented Mar 5, 2024

We are having the same issue in React Native for Asia/Kolkata

@tao-qian
Copy link

tao-qian commented Mar 5, 2024

After doing some research, my impression is that Intl.DateTimeFormat is system specific, and the Asia/Kolkata issue only happens on iOS (at least based on the errors we have seen in Sentry).

Based on facebook/hermes#1100, we decided to manually map Asia/Kolkata to Asia/Calcutta in our code before passing the timezone to date-fns-tz. And that seemed to have helped.

@toduyemi
Copy link

toduyemi commented Apr 3, 2024

I just had this error thrown. After wrestling with it for hours and tracing the issue to the same line as OC, I realized/found the problem was not with my timezone parameter, but with my date string (the first parameter) which was a string. I don't know why this error was getting thrown in my case, but it was very misleading for the error to flag where it did with the message it did. After changing to a UTC epoch timestamp (number), I haave has zero problems, including the timezones all of the above commenters have listed.

@gabs-passarinho-garcia
Copy link

Here we are having the same issue with America/Sao_Paulo and America/Cuiaba timezones

@brianpooe
Copy link

having the same issue with Africa/Johannesburg

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

7 participants