MCPcopy Create free account
hub / github.com/csev/py4e / diff

Function diff

code/gmane/Chart.bundle.js:3479–3503  ·  view source on GitHub ↗
(input, units, asFloat)

Source from the content-addressed store, hash-verified

3477 }
3478
3479 function diff (input, units, asFloat) {
3480 var that = cloneWithOffset(input, this),
3481 zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4,
3482 delta, output;
3483
3484 units = normalizeUnits(units);
3485
3486 if (units === 'year' || units === 'month' || units === 'quarter') {
3487 output = monthDiff(this, that);
3488 if (units === 'quarter') {
3489 output = output / 3;
3490 } else if (units === 'year') {
3491 output = output / 12;
3492 }
3493 } else {
3494 delta = this - that;
3495 output = units === 'second' ? delta / 1e3 : // 1000
3496 units === 'minute' ? delta / 6e4 : // 1000 * 60
3497 units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60
3498 units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
3499 units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
3500 delta;
3501 }
3502 return asFloat ? output : absFloor(output);
3503 }
3504
3505 function monthDiff (a, b) {
3506 // difference in months

Callers

nothing calls this directly

Calls 4

cloneWithOffsetFunction · 0.85
normalizeUnitsFunction · 0.85
monthDiffFunction · 0.85
absFloorFunction · 0.85

Tested by

no test coverage detected