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

Year addition perform unexpected result when value is a multiple of 5 #285

Closed
YixiongJiang opened this issue Apr 28, 2021 · 4 comments
Closed

Comments

@YixiongJiang
Copy link

const date = spacetime('2000-01-01 00:00:00');
expect(date.add(30, 'year').format(DateFormat.YYYY_MM_DD_HH_MM_SS)).toBe('2030-01-01 00:00:00');

Expected: "2030-01-01 00:00:00"
Received: "2029-01-01 00:00:00"

It happens when unit is year and when the value is a multiple of 5.

Just curiosity, why not just add value to the year numerically?

@spencermountain
Copy link
Owner

thanks @YixiongJiang good find. I'll check it out.
cheers

@YixiongJiang
Copy link
Author

@spencermountain Thanks, for your more information, I found there is a workaround to avoid this bug:
date.add(30*12, 'month'),
will get correct result: "2030-01-01 00:00:00"

@spencermountain
Copy link
Owner

yikes! will add this to the next release, ideally next week.
thank you

spencermountain added a commit that referenced this issue Aug 6, 2021
@spencermountain
Copy link
Owner

fixed in v6.16.3 - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants