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

Fix infinite loop caused by fraction value in businessAdd (fixes #55) #59

Merged
merged 4 commits into from
Dec 4, 2018

Conversation

avenue19
Copy link
Contributor

Sorry, my first PR and I uploaded one entire file instead of editing on web. I wasn't able to push from my local clone due to proxy issue.

Fix: Fractional day causes infinite loop in businessAdd eduolalo#55
Added test for Fractional day causes infinite loop in businessAdd eduolalo#55
@mcdado mcdado changed the title Avenue19 patch 1 Fix infinite loop caused by fraction value in businessAdd (fixes #55) Nov 29, 2018
@mcdado
Copy link
Collaborator

mcdado commented Nov 29, 2018

Hi, thanks for sending the PR! I see that there are problems with whitespace causing the whole file to diff (you can see it by going to the "Files changed" tab in this PR page and on the right open "Diff settings" and select "Hide whitespace changes".

Anyway, I'll review it and in case fix the problems 😉

index.js Outdated
return day;
}
var signal = number < 0 ? -1 : 1;
var remaining = Math.abs(Math.trunc(number));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is correct, since it doesn't do any rounding.
Moment.js has a specific function for rounding absolute values, take a look:
https://github.com/moment/moment/blob/master/src/lib/utils/abs-round.js

What do you think? Is it worth it to use that four-liner to handle this case here too?

@mcdado
Copy link
Collaborator

mcdado commented Nov 29, 2018

Sorry, my first PR and I uploaded one entire file instead of editing on web. I wasn't able to push from my local clone due to proxy issue.

In this specific case the problem was due to line endings… your commit switches to CRLF (Windows style) instead of the default LF (Unix Style).

Do you mind either fixing it or even better force push to avenue19:avenue19-patch-1 replacing the previous commits with new commits that keep the LF line endings? That would be awesome!

@avenue19
Copy link
Contributor Author

avenue19 commented Dec 2, 2018 via email

@mcdado
Copy link
Collaborator

mcdado commented Dec 3, 2018

I think it was my error causing the whole file diff. I'm a github newbie :/ Thanks for your patience; )

Hey we all were newbie at some point, I sure made similar mistakes in the beginning! 😉
About the diff, as I mentioned the problem is with line endings. If you don't mind I can fix both problems for you and add the absolute value rounding.

@avenue19
Copy link
Contributor Author

avenue19 commented Dec 4, 2018 via email

@mcdado mcdado merged commit 49477ef into eduolalo:master Dec 4, 2018
@eduolalo
Copy link
Owner

eduolalo commented Dec 4, 2018

Thanks guys, I've deployed it to NPM as V1.1.3.

@nbkhope
Copy link

nbkhope commented Dec 5, 2018

Was there a reason why you reset the original date's timestamp when do you businessAdd()? I have a project that relies on it, some test started failing and we realized this new version now resets the timestamp because of this line

https://github.com/kalmecak/moment-business-days/pull/59/files#diff-168726dbe96b3ce427e7fedce31bb0bcR74

var day = this.clone()    .startOf('day'); // <--

We feel like it might affect the whole project, so are sticking with <1.1.3 for the time being.

@avenue19
Copy link
Contributor Author

avenue19 commented Dec 6, 2018 via email

mcdado added a commit that referenced this pull request Dec 6, 2018
Using businessAdd does not reset the time of day.
@mcdado
Copy link
Collaborator

mcdado commented Dec 6, 2018

Was there a reason why you reset the original date's timestamp when do you businessAdd()? I have a project that relies on it, some test started failing and we realized this new version now resets the timestamp because of this line

Sorry, this slipped through review. Do you have some of those tests to contribute this library? That would be great. @avenue19 did add one, the more the better I guess… 😅

superdev807 pushed a commit to superdev807/emprove-common that referenced this pull request Jul 1, 2020
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

Successfully merging this pull request may close these issues.

4 participants