iamkun / iamkun/dayjs

calling `date.tz(instance, timezone)` does not return the same result as `date.tz(instance.format(), timezone)`

Open
#2,522 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
Given a `dayjs` instance, calling `date.tz(instance, timezone)` does not return the same result as `date.tz(instance.format(), timezone)`.

e.g:
```
const dayjs = require("dayjs");
const timezone = require("dayjs/plugin/timezone");
const utc = require("dayjs/plugin/utc");

dayjs.extend(utc);
dayjs.extend(timezone);

(() => {
const input = dayjs("2023-12-06");
const localDate = dayjs.tz(input.format(), "America/Chicago");
const localDate2 = dayjs.tz(input, "America/Chicago");

// logs `false`
console.log(localDate.format() === localDate2.format());
})();
```

**Expected behavior**
`dayjs.tz` should return a consistent result when supplied a `dayjs` instance and a default formatted version of the same `dayjs` instance. More specifically, passing a `dayjs` instance should return the same result as a formatted `dayjs` instance, given that the formatted instance returns the correct result per the docs.

**Information**
- Day.js Version: 1.11.10
- OS: macOS
- Browser: node v20.9.0
- Time zone: n/a

Contributor guide

Open the contributing guide

Research direction

Start by running the Node.js reproduction and reading the timezone plugin behavior for a Day.js instance versus its formatted string. Add or update coverage for the two calls using the shown America/Chicago example, then confirm both results are consistent with the documented behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.