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

The add/subtract function behaves incorrectly on leap year #2698

Open
amrocs opened this issue Jul 24, 2024 · 0 comments
Open

The add/subtract function behaves incorrectly on leap year #2698

amrocs opened this issue Jul 24, 2024 · 0 comments

Comments

@amrocs
Copy link

amrocs commented Jul 24, 2024

The add/subtract function behaves incorrectly on leap year.

[dayjs 1.11.12]
console.log(dayjs('2023-01-01').add(dayjs.duration(365, 'day')).toDate()); // Mon Jan 01 2024 00:00:00 GMT+0900
console.log(dayjs('2024-01-01').add(dayjs.duration(365, 'day')).toDate()); // Wed Jan 01 2025 00:00:00 GMT+0900 <-- wrong
console.log(dayjs('2025-01-01').add(dayjs.duration(365, 'day')).toDate()); // Thu Jan 01 2026 00:00:00 GMT+0900

console.log(dayjs('2024-01-01').subtract(dayjs.duration(365, 'day')).toDate()); // Sun Jan 01 2023 00:00:00 GMT+0900
console.log(dayjs('2025-01-01').subtract(dayjs.duration(365, 'day')).toDate()); // Mon Jan 01 2024 00:00:00 GMT+0900 <-- wrong
console.log(dayjs('2026-01-01').subtract(dayjs.duration(365, 'day')).toDate()); // Wed Jan 01 2025 00:00:00 GMT+0900

[moment.js]
console.log(moment('2023-01-01').add(moment.duration(365, 'day')).toDate()); // Mon Jan 01 2024 00:00:00 GMT+0900
console.log(moment('2024-01-01').add(moment.duration(365, 'day')).toDate()); // Tue Dec 31 2024 00:00:00 GMT+0900 <-- correct
console.log(moment('2025-01-01').add(moment.duration(365, 'day')).toDate()); // Wed Jan 01 2025 00:00:00 GMT+0900

console.log(moment('2024-01-01').subtract(moment.duration(365, 'day')).toDate()); // Sun Jan 01 2023 00:00:00 GMT+0900
console.log(moment('2025-01-01').subtract(moment.duration(365, 'day')).toDate()); // Tue Jan 02 2024 00:00:00 GMT+0900 <-- correct
console.log(moment('2026-01-01').subtract(moment.duration(365, 'day')).toDate()); // Wed Jan 01 2025 00:00:00 GMT+0900

Information

  • Day.js Version: v1.11.12
  • OS: Windows 10
  • Browser: chrome 126
  • Time zone: GMT+0900 (日本標準時)
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