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

Incorrect behavior of dayjs.tz #2720

Open
salmannotkhan opened this issue Sep 4, 2024 · 1 comment
Open

Incorrect behavior of dayjs.tz #2720

salmannotkhan opened this issue Sep 4, 2024 · 1 comment

Comments

@salmannotkhan
Copy link

Describe the bug

const date = new Date() // utc timezone date
// 2024-09-04T10:04:12.774Z

dayjs.tz(date, "Asia/Kolkata").toISOString()
// 2024-09-04T10:04:12.774Z

dayjs.tz(date.toISOString(), "Asia/Kolkata").toISOString()
// 2024-09-04T04:34:12.774Z

Expected behavior

dayjs.tz(date, "Asia/Kolkata").toISOString()
// 2024-09-04T04:34:12.774Z

Information

  • Day.js Version: v1.11.13
  • OS: macOS
  • Browser: Node.js
  • Time zone: UTC
@salmannotkhan
Copy link
Author

I have tracked down the issue. It's here:

if (typeof input !== 'string') {
// timestamp number || js Date || Day.js
return d(input).tz(timezone)
}

It should be

if (typeof input !== 'string') { 
   if (input instanceof Date || input instanceof Day.js) {
      input = input.toISOString() 
   } else {
      // timestamp number
      input = new Date(input).toISOString() // or dayjs(input).toISOString()
   }
 } 

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

1 participant