-
Notifications
You must be signed in to change notification settings - Fork 733
Description
Bug Description
I get RangeError: Incorrect timeZone information provided whenever creating a date formatter with certain valid timezone identifiers.
Example:
new Intl.DateTimeFormat('en-GB', { timeZone: 'US/Eastern', timeZoneName:'long'})
I did some digging and found this issue (#1100) which mentions that Hermes just defers to what time zones are supported by the OS. However, US/Eastern is supported by iOS. Running NSTimeZone(name: "US/Eastern") does give back a valid time zone. Running the above javascript in JavaScriptCore also gives back a valid value.
I dug into the code a bit and Hermes seems to be relying on NSTimeZone.knownTimeZoneNames to determine if a time zone identifier is valid (pointer). NSTimeZone.knownTimeZoneNames does not represent all of the valid time zone identifiers iOS supports. This is even noted in a comment here.
It looks like the issue might be fixed by just trying to initialize an NSTimeZone with the name before raising the exception. If it's not nil then add it to the list of known time zones, otherwise raise the exception. Applying something like this (here):
// b. If the result of IsValidTimeZoneName(timeZone) is false, then
if (!isValidTimeZoneName(timeZone)) {
if ([[NSTimeZone alloc] initWithName:timeZone] != nil) {
validTimeZoneNames().update(timeZone);
} else {
// i. Throw a RangeError exception.
return runtime.raiseRangeError("Incorrect timeZone information provided");
}
}
Thoughts?
Related Issues:
date-fns/tz#32
marnusw/date-fns-tz#264
#1100
React Native version: 0.76.6
OS: iOS