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

Date Calculation Issue with Subtracting a Large Number of Years #2749

Open
YOUNGmaxer opened this issue Oct 17, 2024 · 2 comments
Open

Date Calculation Issue with Subtracting a Large Number of Years #2749

YOUNGmaxer opened this issue Oct 17, 2024 · 2 comments

Comments

@YOUNGmaxer
Copy link

Describe the bug
I've encountered an issue with dayjs when subtracting a large number of years from a date. Specifically, when I attempt to subtract 129 years from a date, the resulting date is incorrect.
image

Expected behavior
The date after subtracting 129 years should accurately reflect the original month and day, not resetting to the first day of the month.

Information

  • Day.js Version v1.11.12
  • OS: Mac OS
  • Browser Chrome/129.0.0.0
  • Time zone: America/Toronto
@isaiah2004
Copy link

hey i think this is because of the way 1 y maybe defined as 365 days. or the Definition of the term year itself. what is your expected behaviour?

@YOUNGmaxer
Copy link
Author

YOUNGmaxer commented Oct 24, 2024

Expected behaviour:
dayjs().tz('America/Toronto').format('YYYY-MM-DD') // '2024-10-17'
dayjs().tz('America/Toronto').subtract(129, 'y').format('YYYY-MM-DD') // '1895-10-17'

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

2 participants