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 bug where diff returns -0 in month-related diffs #3059

Closed
wants to merge 1 commit into
base: develop
from

Conversation

Projects
None yet
4 participants
@maggiepint
Member

maggiepint commented Mar 22, 2016

Fixes #2908.

I wish there were simpler code for this, but as far as I am aware the only way to get rid of the negative zero is to explicitly check for it and replace it with zero.

Fun fact - this bug created a stack overflow question with a ton of upvotes: http://stackoverflow.com/questions/31599665/javascript-detecting-the-difference-between-positive-zero-and-negative-zero

Edit: Tim made my code good. Lesson learned.

@@ -57,5 +57,7 @@ function monthDiff (a, b) {
adjust = (b - anchor) / (anchor2 - anchor);
}
return -(wholeMonthDiff + adjust);

This comment has been minimized.

@timrwood

timrwood Mar 22, 2016

Member

What about return -(wholeMonthDiff + adjust) || 0;?

This comment has been minimized.

@maggiepint

maggiepint Mar 22, 2016

Member

YES! I knew that could be made shorter. Thanks @timrwood

@mj1856 mj1856 added the Bug-fix label Mar 23, 2016

@mj1856 mj1856 added this to the 2.13.0 milestone Mar 23, 2016

@ichernev

This comment has been minimized.

Contributor

ichernev commented Apr 12, 2016

Thanks @maggiepint. At least we taught a floating point lesson to the js community :)

@ichernev

This comment has been minimized.

Contributor

ichernev commented Apr 16, 2016

Merged in 18d65b9

@ichernev ichernev closed this Apr 16, 2016

ichernev added a commit that referenced this pull request Apr 16, 2016

Merge pull request #3059 from maggiepint:diffNegZero
fix bug where diff returns -0 in month-related diffs

@maggiepint maggiepint deleted the maggiepint:diffNegZero branch May 14, 2016

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