calling `date.tz(instance, timezone)` does not return the same result as `date.tz(instance.format(), timezone)`
- 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
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