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

Reimplement month diff logic #2133

Merged
merged 1 commit into from Dec 30, 2014
Merged

Conversation

ichernev
Copy link
Contributor

The new algorithm to compute month differences between two moments (used in
diff(a, 'month|quarter|year')), is as follows:

  • take the whole number of months between the two dates (ignoring day-of-month
    and hour) -- wholeMonthDiff
  • the above is adjusted linearly by how much the second date is away from the
    whole-month-diff-date (the date where the result would be exactly
    wholeMonthDiff)

This algorithm makes sure that dates that are exact number of months apart
would return whole numbers (like previous algorithm), but also fixes a few edge
cases that the old agorithm failed to do, like when the first moment is close
to the end of a long month and the second moment was in the begining of a short
month (end of Jan to begining of Feb for example).

Fixes #2026

The new algorithm to compute month differences between two moments (used in
`diff(a, 'month|quarter|year')`), is as follows:
- take the whole number of months between the two dates (ignoring day-of-month
  and hour) -- whole-month-diff
- the above is adjusted by how much the second date is away from the
  whole-month-diff-date (the date where the result would be exactly
  whole-month-diff)

This algorithm makes sure that dates that are exact number of months apart
would return whole numbers (like previous algorithm), but also fixes a few edge
cases that the old agorithm failed to do, like when the first moment is close
to the end of a long month and the second moment was in the begining of a short
month (end of Jan to begining of Feb for example).

Fixes moment#2026
@ichernev ichernev merged commit ae83a69 into moment:develop Dec 30, 2014
ichernev added a commit that referenced this pull request Dec 30, 2014
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.

month comparison currently broken in EST
1 participant