timrwood/moment — pull request #571 by timrwood (2013-01-10 18:26:33+00:00)
Title: Fix month and year diffs

This is a potential solution to the buggy month/year diffs. However, when working on this I ran into some tricky problems, so I want to outline them here for posterity.

There are a few different ways to calculate the difference in years. The first way is to compare the percentages through the year.

```javascript
startPercent = 45 / 365; // 0.1232876712328767
endPercent = 57 / 365; // 0.15616438356164383
diffPercent = endPercent - startPercent; // 0.03287671232876713
```

However, this has unexpected results when crossing leap years due to the extra day. 45 days into the year is a slightly smaller percentage on years with 366 days than years with 365 days.

```javascript
startPercent = 45 / 365; // 0.1232876712328767
endPercent = 45 / 366; // 0.12295081967213115
diffPercent = endPercent - startPercent; // -0.0003368515607455602
```

The solution I am proposing is that we use the percentages through the months divided by 12.

We calculate the percentage through the year with month accuracy (0/12, 1/12, 2/12 ... 11/12).

We then calculate the percentages through the start and end months with millisecond accuracy. For example, (189798626 / (31 * 24 * 60 * 60 * 1000)).

Then, the combination of those two diffs results in a slightly more expected result.

An added bonus to this methodology is that we can use the same calculation for difference in months. Month diff = year diff * 12.