MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / diff

Function diff

tests/test_code/js/moment/moment.js:3828–3875  ·  view source on GitHub ↗
(input, units, asFloat)

Source from the content-addressed store, hash-verified

3826 }
3827
3828 function diff(input, units, asFloat) {
3829 var that, zoneDelta, output;
3830
3831 if (!this.isValid()) {
3832 return NaN;
3833 }
3834
3835 that = cloneWithOffset(input, this);
3836
3837 if (!that.isValid()) {
3838 return NaN;
3839 }
3840
3841 zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
3842
3843 units = normalizeUnits(units);
3844
3845 switch (units) {
3846 case 'year':
3847 output = monthDiff(this, that) / 12;
3848 break;
3849 case 'month':
3850 output = monthDiff(this, that);
3851 break;
3852 case 'quarter':
3853 output = monthDiff(this, that) / 3;
3854 break;
3855 case 'second':
3856 output = (this - that) / 1e3;
3857 break; // 1000
3858 case 'minute':
3859 output = (this - that) / 6e4;
3860 break; // 1000 * 60
3861 case 'hour':
3862 output = (this - that) / 36e5;
3863 break; // 1000 * 60 * 60
3864 case 'day':
3865 output = (this - that - zoneDelta) / 864e5;
3866 break; // 1000 * 60 * 60 * 24, negate dst
3867 case 'week':
3868 output = (this - that - zoneDelta) / 6048e5;
3869 break; // 1000 * 60 * 60 * 24 * 7, negate dst
3870 default:
3871 output = this - that;
3872 }
3873
3874 return asFloat ? output : absFloor(output);
3875 }
3876
3877 function monthDiff(a, b) {
3878 if (a.date() < b.date()) {

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