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

Timezone plugin returns incorrect values or null #2207

Open
dawidzawadzki opened this issue Jan 15, 2023 · 7 comments
Open

Timezone plugin returns incorrect values or null #2207

dawidzawadzki opened this issue Jan 15, 2023 · 7 comments

Comments

@dawidzawadzki
Copy link

dawidzawadzki commented Jan 15, 2023

Describe the bug

The Timezone plugin returns incorrect values or null on iOS when Hermes engine is enabled.

Information

  • Day.js: 1.11.7
  • OS: iOS
  • React Native: 0.71
  • Time zone: GMT+01:00

Steps to reproduce

  1. npx react-native init AwesomeProject
  2. yarn add dayjs

Code example

import React from 'react';
import {SafeAreaView} from 'react-native';
import dayjs from 'dayjs';
import timezoneDayjsPlugin from 'dayjs/plugin/timezone';
import utcDayjsPlugin from 'dayjs/plugin/utc';

dayjs.extend(utcDayjsPlugin);
dayjs.extend(timezoneDayjsPlugin);

const App = () => {
  // #1 Converting to a timezone
  const timestamp = '2013-11-18 11:55';
  const tz = 'Asia/Taipei';

  console.log(
    'Converting to a timezone',
    dayjs
      .utc('2013-11-18 11:55')
      .tz('Asia/Taipei')
      .format(),
  );

  // #2 Parsing in a timezone
  console.log(
    'Parsing in a timezone',
    dayjs.tz(timestamp, tz).format(),
  );

  return <SafeAreaView />;
};
export default App;

Actual behavior

 LOG  Converting to a timezone Invalid Date
 LOG  Parsing in a timezone 2013-11-18T12:08:00+07:55

Expected behavior

 LOG  Converting to a timezone 2013-11-18T19:55:00+08:00
 LOG  Parsing in a timezone 2013-11-18T11:55:00+08:00

For React Native < 0.70 timezone plugin doesn't work at all, right now it works but returned values are incorrect.

@nemphys
Copy link

nemphys commented Jan 19, 2023

This is driving me nuts!

I have been using dayjs and the timezone plugin in a node project for more than 2 years now and, just recently (and without any change related to dayjs whatsoever) it started producing invalid dates whenever the timezone plugin is used!

What is even weirder is that it only happens on my Mac mini, whereas everything looks normal on several ubuntu servers where the app is also running. All machines have the same node version (16.19.0).

Any ideas?

@nemphys
Copy link

nemphys commented Jan 19, 2023

Nevermind, apparently this happened due to the homebrew icu4c update to 72.1...
The good news is that node 18.3.0 seems to have mitigated the issue and works properly with the new icu version.

@Pareder
Copy link

Pareder commented Jan 30, 2023

I faced the same issue, on iOS everything is good, but on Android I got null and Invalid Date. Maybe it is somehow related to facebook/react-native#28097. Have you found a solution, @dawidzawadzki ?

When using something like this

dayjs('2023-01-01').format()

everything is good

But when using

dayjs('2023-01-01').tz()

null is returned.

@dawidzawadzki
Copy link
Author

@Pareder Unfortunately not. I've disabled Hermes on iOS for now.

@durgaswaroop
Copy link

durgaswaroop commented Jun 4, 2023

This is happening for me too. But it seems to be random. In one run it gives proper values and in another they are all null values. I was debugging the issue for so long!!

Also, it is only happening on an android physical device. During unit testing, everything works fine.

@KingAmo
Copy link

KingAmo commented Apr 7, 2024

any update on this?

@almiavicas
Copy link

Hi, this started to be an issue for me as well. I'll dive into the PR #2227 and add some test cases there

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

6 participants