dayjs
dayjs copied to clipboard
`dayjs().tz()` not working as expected with math operations
Describe the bug
dayjs().tz()
with an operation like .subtract()
or .add()
get wrong time, see an example below:
const dayjs = require('dayjs');
const timezone = require('dayjs/plugin/timezone');
const utc = require('dayjs/plugin/utc');
dayjs.extend(utc);
dayjs.extend(timezone);
const initialTime = dayjs()
.tz('utc')
.subtract(15, 'm')
.format('YYYY-MM-DD HH:mm:ss');
const finalTime = dayjs().tz('utc').format('YYYY-MM-DD HH:mm:ss');
console.log(`Timezone: ${dayjs.tz.guess()}`); // output: Timezone: America/Sao_Paulo
console.log(`Initial time: ${initialTime}`); // output: Initial time: 2022-03-10 15:06:15
console.log(`Final time: ${finalTime}`); // output: Final time: 2022-03-10 12:21:15
Expected behavior I expected same hour with 15 minutes of difference, something like:
- Initial time: 2022-03-10 12:06:15
- Final time: 2022-03-10 12:21:15
--
I looked at the issues of this library and it seems that there are several unexpected behaviors in relation to .tz()
,
Issue that compile bugs. Do you need any help with this?
Information
- Day.js Version: v1.10.8
- OS: macOS Big Sur 11.6.1
- Browser: Not browser, but Node.js v16.13.1
I'm using React native and dayjs v1.11.1.
dayjs("2014-06-01 12:00").tz("America/New_York")
Code above returns null. Does anyone know why?
Running into this as well in React Native
Cross-referencing with:
https://github.com/iamkun/dayjs/issues/1377
Timezone support seems broken with Hermes/Intl. Has any one got this to work?