]> git.ipfire.org Git - thirdparty/moment.git/commit
Reimplement month diff logic 2133/head
authorIskren Chernev <iskren.chernev@gmail.com>
Mon, 29 Dec 2014 11:18:18 +0000 (13:18 +0200)
committerIskren Chernev <iskren.chernev@gmail.com>
Tue, 30 Dec 2014 07:43:35 +0000 (09:43 +0200)
commitae83a69f645236b671a4fe6e07c6cb2643a195e8
tree5f632c24da64abbf815abff7db5bc276aa764486
parent75ed8e6e7d0dcb2dd1d2b9f5efd7c41c597bcb21
Reimplement month diff logic

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 #2026
moment.js
test/moment/diff.js