dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

`dayjs().tz()` not working as expected with math operations

Open joaobispo2077 opened this issue 2 years ago • 2 comments

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

joaobispo2077 avatar Mar 10 '22 12:03 joaobispo2077

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?

olgaababic avatar Apr 21 '22 10:04 olgaababic

Running into this as well in React Native

dorthwein avatar Jul 21 '22 19:07 dorthwein

Cross-referencing with:

https://github.com/iamkun/dayjs/issues/1377

Timezone support seems broken with Hermes/Intl. Has any one got this to work?

ospfranco avatar Sep 23 '22 14:09 ospfranco