Incorrect result: 3:00:01 minus 2 second = 1:59:59 depend on env.TZ
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
`subtract()` method may return an incorrect result with `dayjs/plugin/timezone` depend on the place where you runs the script.
If you run it at Tokyo, it returns a correct result.
If you run the same code at New York, however, it returns an incorrect value.
Note that we don't have the DST daylight saving time system in Tokyo.
And in the U.S., March 13 was the day to switch from STD to DST at 2022.
```js
const dayjs = require("dayjs");
dayjs.extend(require("dayjs/plugin/utc"));
dayjs.extend(require("dayjs/plugin/timezone"));
const dt = new Date("2022/03/13 03:00:01 -07:00");
const utc = +dt;
const LA = "America/Los_Angeles";
const FMT = "YYYY-MM-DDTHH:mm:ssZ";
let t;
// If you are in Tokyo
process.env.TZ = "Asia/Tokyo";
t = dayjs(dt).tz(LA).subtract(2, "second");
console.log(t.format(FMT), +t - utc);
// => 2022-03-13T02:59:59-07:00 -2000 (not so bad)
// If you are in New York
process.env.TZ = "America/New_York";
t = dayjs(dt).tz(LA).subtract(2, "second");
console.log(t.format(FMT), +t - utc);
// => 2022-03-13T01:59:59-07:00 -3602000 (incorrect)
```
**Expected behavior**
`subtract()` method should return the incorrect result wherever you run the script like `moment-timezone` have done.
```js
const moment = require("moment");
require("moment-timezone");
// If you are in New York
process.env.TZ = "America/New_York";
t = moment(dt).tz(LA).subtract(2, "second");
console.log(t.format(FMT), +t - utc);
// => 2022-03-13T01:59:59-08:00 -2000 (perfect)
```
**Information**
- Day.js Version: 1.11.6
- OS: macOS
- Time zone: `America/New_York`
Contributor guide
Assessment
This issue has not been assessed yet.