import absFloor from '../utils/abs-floor';
import { cloneWithOffset } from '../units/offset';
import { normalizeUnits } from '../units/aliases';

export function diff (input, units, asFloat) {
    var that,
        zoneDelta,
        delta, output;

    if (!this.isValid()) {
        return NaN;
    }

    that = cloneWithOffset(input, this);

    if (!that.isValid()) {
        return NaN;
    }

    zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;

    units = normalizeUnits(units);

    if (units === 'year' || units === 'month' || units === 'quarter') {
        output = monthDiff(this, that);
        if (units === 'quarter') {
            output = output / 3;
        } else if (units === 'year') {
            output = output / 12;
        }
    } else {
        delta = this - that;
        output = units === 'second' ? delta / 1e3 : // 1000
            units === 'minute' ? delta / 6e4 : // 1000 * 60
            units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60
            units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
            units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
            delta;
    }
    return asFloat ? output : absFloor(output);
}

function monthDiff (a, b) {
    // difference in months
    var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
        // b is in (anchor - 1 month, anchor + 1 month)
        anchor = a.clone().add(wholeMonthDiff, 'months'),
        anchor2, adjust;

    if (b - anchor < 0) {
        anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
        // linear across the month
        adjust = (b - anchor) / (anchor - anchor2);
    } else {
        anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
        // linear across the month
        adjust = (b - anchor) / (anchor2 - anchor);
    }

    //check for negative zero, return zero if negative zero
    return -(wholeMonthDiff + adjust) || 0;
}

@@ -499,162 +499,107 @@
     
-if (units === 'year' %7C%7C units === 'month' %7C%7C units === 'quarter') %7B%0A        output = monthDiff(
+output = monthDiff(this, that);%0A    delta = 
 this
-,
+ -
  that
-)
 ;
+%0A
 %0A    
-    if
+switch
  (units
- === 'quarter') %7B%0A           
+) %7B%0A        case 'year':
  out
@@ -613,17 +613,25 @@
 utput / 
-3
+12; break
 ;%0A      
@@ -636,162 +636,112 @@
     
-%7D else if (units === 'year') %7B%0A            output = output / 12;%0A        %7D%0A    %7D else %7B%0A        delta = this - that;%0A        output = units === 'second' ?
+case 'month': break;%0A        case 'quarter': output = output / 3; break;%0A        case 'second': output =
  del
@@ -748,18 +748,24 @@
 ta / 1e3
- :
+; break;
  // 1000
@@ -777,32 +777,31 @@
     
-    units === 'minute' ?
+case 'minute': output =
  del
@@ -808,18 +808,24 @@
 ta / 6e4
- :
+; break;
  // 1000
@@ -842,30 +842,29 @@
     
-    units === 'hour' ?
+case 'hour': output =
  del
@@ -872,18 +872,24 @@
 a / 36e5
- :
+; break;
  // 1000
@@ -911,29 +911,28 @@
     
-    units === 'day' ?
+case 'day': output =
  (de
@@ -955,18 +955,24 @@
  / 864e5
- :
+; break;
  // 1000
@@ -1011,30 +1011,29 @@
     
-    units === 'week' ?
+case 'week': output =
  (de
@@ -1057,18 +1057,24 @@
 / 6048e5
- :
+; break;
  // 1000
@@ -1109,27 +1109,41 @@
 dst%0A        
-   
+default: output =
  delta;%0A    
@@ -1144,16 +1144,17 @@
 ;%0A    %7D%0A
+%0A
     retu

convert long ternary operator to switch for easier readability