dayjs
dayjs copied to clipboard
add() result is wrong with timezone
Describe the bug
if a dayjs object have a Europe/London timezone, adding time to it give a wrong result.
reproduction:
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
dayjs.extend(utc);
dayjs.extend(timezone);
const t = dayjs(1709695253000).tz("Europe/London");
const t1 = t.add(1, "hour");
console.log(t.valueOf(), t.utcOffset(), t.format()); // 1709695253000 0 2024-03-06T03:20:53Z
console.log(t1.valueOf(), t1.utcOffset(), t1.format()); // 1709698853000 0 2024-03-05T20:20:53Z
https://codesandbox.io/p/sandbox/dayjs-bug-29pl4w?file=%2Fsrc%2Findex.mjs%3A4%2C1
The add 1 hour result is less than the original time! It is wrong!
Other timezone with offset "+00:00" like Etc/UTC and Etc/Zulu can also reproduce this bug.
Expected behavior add() result should be correct. In this demo, t1.format() should be "2024-03-06T04:20:53Z"
Information
- Day.js Version 1.11.10
- OS: MacOS
- Browser: chrome 121.0.6167.160
- My Computer time zone: (UTC+08:00) Asia/Shanghai
The result I got is
console.log(t.valueOf(), t.utcOffset(), t.format()); // 1709695253000 0 2024-03-06T03:20:53Z
console.log(t1.valueOf(), t1.utcOffset(), t1.format()); // 1709698853000 0 2024-03-06T04:20:53Z
Looks fine?
The result I got is
console.log(t.valueOf(), t.utcOffset(), t.format()); // 1709695253000 0 2024-03-06T03:20:53Z console.log(t1.valueOf(), t1.utcOffset(), t1.format()); // 1709698853000 0 2024-03-06T04:20:53ZLooks fine?
Ok they fixed this issue since 1.11.12