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: Incorrect timeZone information provided #32

Open
CoderCharlie opened this issue Dec 14, 2024 · 7 comments
Open

RangeError: Incorrect timeZone information provided #32

CoderCharlie opened this issue Dec 14, 2024 · 7 comments

Comments

@CoderCharlie
Copy link

CoderCharlie commented Dec 14, 2024

Env:
Mac: 15.1.1
node: v18.20.2

"@date-fns/tz": "^1.2.0",
"date-fns": "^4.1.0",
"react-native": "0.73.4",

When I run

TZDate.tz(timezone)

or

const now = new Date()
new Intl.DateTimeFormat("en-GB", {
          timeZone:timezone,
          timeZoneName: "long",
        }).format(now)

I got this error: RangeError: Incorrect timeZone information provided

So I added below code to validate

      const validateTimeZone = (timeZone) => {
        try {
          new Intl.DateTimeFormat("en-US", { timeZone })
          return true // Valid timezone
        } catch (e) {
          if (e instanceof RangeError) {
            return false // Invalid timezone
          }
          throw e // Other errors
        }
      }

    const timezone = 'Asia/Kolkata'
      console.log(
        `timezone ${timezone} is ${
          validateTimeZone(timezone) ? "valid" : "invalid"
        }`,
      )

output

timezone Asia/Kolkata is invalid
@CoderCharlie
Copy link
Author

This is probably unrelated to the library, close this issue.

@CoderCharlie
Copy link
Author

Re-open this as this is related to the library. Since date-fns/tz is using Intl.DateTimeFormat to convert timezones, and Intl.DateTimeFormat is not fully supported in the react-native env. This makes the library incompatible in for react-native apps.

@seanblonien
Copy link

I also just learned this the hard way, my react-native Android app is now crashing since I am migrating over

It probably is react-native's fault for not fully implementing the API, and yet it is still this library's problem. so if possible to get this compatible with react-native that would be great

@kossnocorp
Copy link
Member

I should solve it, and I don't think it's impossible, but I need some help setting up a proper environment to test it. If somebody can help me set up a minimal repro repo, I will pull it and integrate it into CI.

@seanblonien
Copy link

here is a quick repo in Expo showing it failing on both iOS and Android
https://snack.expo.dev/@seanblonien_flybodies/date-fns-tz-android-error-repro

image
image

@aizerin
Copy link

aizerin commented Jan 15, 2025

I'm using this library with react-native on Android and IOS with this patch #17 without any issues so far.

@cyanzule
Copy link

cyanzule commented Jan 24, 2025

I should solve it, and I don't think it's impossible, but I need some help setting up a proper environment to test it. If somebody can help me set up a minimal repro repo, I will pull it and integrate it into CI.

@kossnocorp seeing this seems to be similar to #17, on incomplete or erroneous TimeZone implementation on React Native's part, I'd be willing on attempting to create a replicable repro, based on all the expo snacks the community has offered on this issue and see if I could write some tests to replicate these and any possible fix, like my suggested patch.

My worry is that this seems to be strictly an issue on the native side, as in you'd need an E2E setup on your CI pipelines to properly test it, as any node-run tests would be false negative failures (oh I hate that double negative, lol). That's something I don't have experience in but know ahead of time that it is a lot of effort and possibly expensive, like needing a mac CI runner for any iOS build.

The proper-est solution would be to escalate the issue as well to the RN's team. Going to think how one could go about that, as having inconsistent output is not necessarily a bug on their end, browsers do that all the time as well.

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

5 participants