date-fns-tz icon indicating copy to clipboard operation
date-fns-tz copied to clipboard

Invalid time value

Open eq0rip opened this issue 2 years ago • 8 comments

While the library is working well on most parts. We recently started seeing error report on Sentry Invalid time value on some of the Android 6 devices. But we were concerned when recently we had the same case reported on Android 12 device too. We debugged on emulater for android 6 and were able to recreate the error and turns our tzTokenizeDate is returning monthName instead of monthNumber.

eq0rip avatar Jul 05 '22 14:07 eq0rip

I have sent a PR if someone has same issue and wants to use the solution. https://github.com/marnusw/date-fns-tz/pull/190

eq0rip avatar Jul 05 '22 15:07 eq0rip

Having the same issue only on Android devices. I've found out that getTimezoneOffset function returns NaN in all cases (tried with my local timezone and some other timezones). My current package version is 1.3.4.

dmytrokruhlyi avatar Jul 12 '22 09:07 dmytrokruhlyi

same, any fix?

farzd avatar Aug 16 '22 05:08 farzd

Same here, working on iOS and in everywhere else. But on Android, it returns Date { NaN } (Invalid Time) and crashes the app.

luizfelipelaviola avatar Oct 05 '22 19:10 luizfelipelaviola

@luizfelipelaviola I've found a solution. In your android/app/build.gradle just replace the line def jscFlavor = 'org.webkit:android-jsc:+' with def jscFlavor = 'org.webkit:android-jsc-intl:+' and it works. There was an issue with Android build system.
You can find more details here.

dimakruhlyi avatar Oct 05 '22 19:10 dimakruhlyi

@luizfelipelaviola I've found a solution. In your android/app/build.gradle just replace the line def jscFlavor = 'org.webkit:android-jsc:+' with def jscFlavor = 'org.webkit:android-jsc-intl:+' and it works. There was an issue with Android build system. You can find more details here.

Thanks for sharing that... But this is not working with Hermes. I found the updated documentation for date-fns-tz https://github.com/marnusw/date-fns-tz#usage-with-android Time to move on to another solution...

luizfelipelaviola avatar Oct 05 '22 20:10 luizfelipelaviola

@luizfelipelaviola @dimakruhlyi @dmytrokruhlyi

have you tried my PR https://github.com/marnusw/date-fns-tz/pull/190

?

it's sorted on my side with this workaround

eq0rip avatar Oct 05 '22 21:10 eq0rip

I'm using RN v0.66.3 for Android with Hermes. I tried the #190 from @eq0rip and editing the build.gradle as @dimakruhlyi said but both didn't work.

The solution was follow the @marnusw recommendation and start using polyfills by Format.JS on the date-fns-tz docs.

I've installed and added all polyfills and dependencies from Format.JS and everything is working very well right now.

Just install and put this on the top of your main index.tsx file:

import '@formatjs/intl-locale/polyfill'
import '@formatjs/intl-getcanonicallocales/polyfill'
import '@formatjs/intl-pluralrules/polyfill'
import '@formatjs/intl-pluralrules/locale-data/en'
import '@formatjs/intl-numberformat/polyfill'
import '@formatjs/intl-numberformat/locale-data/en'
import '@formatjs/intl-datetimeformat/polyfill'
import '@formatjs/intl-datetimeformat/locale-data/en'

Hope that helps someone else.

See also: https://github.com/formatjs/formatjs/issues/1967

luizfelipelaviola avatar Oct 05 '22 23:10 luizfelipelaviola