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

Problem with timezones in react native #2372

Open
VictorPulzz opened this issue Jul 12, 2023 · 11 comments
Open

Problem with timezones in react native #2372

VictorPulzz opened this issue Jul 12, 2023 · 11 comments

Comments

@VictorPulzz
Copy link

Describe the bug
When I try convert date to select timezone, I got 'Invalid date'.
I know that we can use polyfill from this thread but it's look terrible.

console.log(dayjs('2023-07-11T10:00:00').tz('Australia/Melbourne').format('YYYY-MM-DD HH:mm'));
console.log(dayjs('2023-07-11T10:00:00').tz('Australia/Melbourne').utc().format('YYYY-MM-DD HH:mm'));

got:
image

Expected behavior
Timezone is working on react-native

Information

  • Day.js Version [1.11.7]
  • OS: MacOS m1
  • React-native [0.71.8]
  • Time zone: [not important]
@Willham12
Copy link

same issue here

@sam-houle1
Copy link

Same issue, @VictorPulzz @Willham12 did you guys found anything to fix this issue ?

@Willham12
Copy link

No, i'm still using momentjs

@VictorPulzz
Copy link
Author

VictorPulzz commented Oct 13, 2023

@sam-houle1 Unfortunately, without pollyfil, it doest work. You can try set offset monually like this:

// get offset use any date
const getOffset = dayjs.tz('2023-09-04 12:00:00', tz).utcOffset();
// set offset for any date
dayjs.utc(date).utcOffset(getOffset)

@badalsaibo
Copy link

@Willham12 Does momentjs not have timezones issue in React Native? If no, then I will be migrating.

@Willham12
Copy link

No issues with momentjs but it's deprecated.

@rklomp
Copy link

rklomp commented Jan 2, 2024

Same issue here. Switching back to momentjs for now :(

@alexkev
Copy link

alexkev commented Jan 24, 2024

I believe moment has the same issue: see this problem here: https://stackoverflow.com/questions/71421582/moment-returning-an-invalid-date-while-using-hermes-js-engine.

@alexkev
Copy link

alexkev commented Jan 24, 2024

This caused by hermes; follow this issue: facebook/hermes#865

@shuo-hiwintech
Copy link

I'm currently using moment and so far he's working fine.

@milesingrams
Copy link

We were dealing with this in our codebase and I was able to fix by patching a few lines of the dayjs/timezone plugin code. Here is the fix. Hopefully it can be merged!
#2843

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

8 participants