dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

Timezone plugin returns incorrect values or null

Open dawidzawadzki opened this issue 2 years ago • 7 comments

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.

dawidzawadzki avatar Jan 15 '23 20:01 dawidzawadzki

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 avatar Jan 19 '23 21:01 nemphys

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.

nemphys avatar Jan 19 '23 23:01 nemphys

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 https://github.com/facebook/react-native/issues/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.

Pareder avatar Jan 30 '23 15:01 Pareder

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

dawidzawadzki avatar Jan 30 '23 22:01 dawidzawadzki

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.

durgaswaroop avatar Jun 04 '23 08:06 durgaswaroop

any update on this?

KingAmo avatar Apr 07 '24 08:04 KingAmo

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

almiavicas avatar May 22 '24 19:05 almiavicas