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

Infinite loop when adding to invalid dates. #36

Open
hermann-p opened this issue May 31, 2023 · 0 comments
Open

Infinite loop when adding to invalid dates. #36

hermann-p opened this issue May 31, 2023 · 0 comments

Comments

@hermann-p
Copy link

hermann-p commented May 31, 2023

When doing the following, I get an infinite loop:

const x = dayjs(null).businessDaysAdd(1);

This is probably due to the while loop in the businessDaysAdd method. It proceeds to the next day, reduces the days to add by one if that next day is a business day, and repeats until days to add reach zero.
When the starting date was invalid, no day will ever be a business day and the remaining days will never decrease.

My advice would be changing line 23 in index.js from

while (daysRemaining > 0) {

to something like

while (currentDay.isValid() && daysRemaining > 0) {

plus adding a test.

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