corrade-nucleus-nucleons – Blame information for rev 38

Subversion Repositories:
Rev:
Rev Author Line No. Line
38 office 1 import absFloor from '../utils/abs-floor';
2 import { cloneWithOffset } from '../units/offset';
3 import { normalizeUnits } from '../units/aliases';
4  
5 export function diff (input, units, asFloat) {
6 var that,
7 zoneDelta,
8 delta, output;
9  
10 if (!this.isValid()) {
11 return NaN;
12 }
13  
14 that = cloneWithOffset(input, this);
15  
16 if (!that.isValid()) {
17 return NaN;
18 }
19  
20 zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
21  
22 units = normalizeUnits(units);
23  
24 if (units === 'year' || units === 'month' || units === 'quarter') {
25 output = monthDiff(this, that);
26 if (units === 'quarter') {
27 output = output / 3;
28 } else if (units === 'year') {
29 output = output / 12;
30 }
31 } else {
32 delta = this - that;
33 output = units === 'second' ? delta / 1e3 : // 1000
34 units === 'minute' ? delta / 6e4 : // 1000 * 60
35 units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60
36 units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
37 units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
38 delta;
39 }
40 return asFloat ? output : absFloor(output);
41 }
42  
43 function monthDiff (a, b) {
44 // difference in months
45 var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
46 // b is in (anchor - 1 month, anchor + 1 month)
47 anchor = a.clone().add(wholeMonthDiff, 'months'),
48 anchor2, adjust;
49  
50 if (b - anchor < 0) {
51 < 0) { anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
52 < 0) { // linear across the month
53 < 0) { adjust = (b - anchor) / (anchor - anchor2);
54 < 0) { } else {
55 < 0) { anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
56 < 0) { // linear across the month
57 < 0) { adjust = (b - anchor) / (anchor2 - anchor);
58 < 0) { }
59  
60 < 0) { //check for negative zero, return zero if negative zero
61 < 0) { return -(wholeMonthDiff + adjust) || 0;
62 < 0) {}