| 3875 | } |
| 3876 | |
| 3877 | function monthDiff(a, b) { |
| 3878 | if (a.date() < b.date()) { |
| 3879 | // end-of-month calculations work correct when the start month has more |
| 3880 | // days than the end month. |
| 3881 | return -monthDiff(b, a); |
| 3882 | } |
| 3883 | // difference in months |
| 3884 | var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month()), |
| 3885 | // b is in (anchor - 1 month, anchor + 1 month) |
| 3886 | anchor = a.clone().add(wholeMonthDiff, 'months'), |
| 3887 | anchor2, |
| 3888 | adjust; |
| 3889 | |
| 3890 | if (b - anchor < 0) { |
| 3891 | anchor2 = a.clone().add(wholeMonthDiff - 1, 'months'); |
| 3892 | // linear across the month |
| 3893 | adjust = (b - anchor) / (anchor - anchor2); |
| 3894 | } else { |
| 3895 | anchor2 = a.clone().add(wholeMonthDiff + 1, 'months'); |
| 3896 | // linear across the month |
| 3897 | adjust = (b - anchor) / (anchor2 - anchor); |
| 3898 | } |
| 3899 | |
| 3900 | //check for negative zero, return zero if negative zero |
| 3901 | return -(wholeMonthDiff + adjust) || 0; |
| 3902 | } |
| 3903 | |
| 3904 | hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ'; |
| 3905 | hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]'; |