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

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

Open
joaobispo2077 opened this issue Mar 10, 2022 · 3 comments
Open

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

joaobispo2077 opened this issue Mar 10, 2022 · 3 comments

Comments

@joaobispo2077
Copy link

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
@olgaababic
Copy link

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?

@dorthwein
Copy link

Running into this as well in React Native

@ospfranco
Copy link

Cross-referencing with:

#1377

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

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

4 participants