dayjs
dayjs copied to clipboard
Timezone plugin returns incorrect values or null
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
-
npx react-native init AwesomeProject
-
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.
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?
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.
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 Unfortunately not. I've disabled Hermes on iOS for now.
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.
any update on this?
Hi, this started to be an issue for me as well. I'll dive into the PR #2227 and add some test cases there