From: Rocky Meza Date: Sat, 7 Apr 2012 15:43:56 +0000 (-0600) Subject: Simplified the dateAddRemove helper using the Duration object. X-Git-Tag: 1.6.0~1^2~6^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7375b247da17bea560e1856adee2764f22638ba;p=thirdparty%2Fmoment.git Simplified the dateAddRemove helper using the Duration object. --- diff --git a/moment.js b/moment.js index a52e4f30e..4b6413aeb 100644 --- a/moment.js +++ b/moment.js @@ -60,19 +60,22 @@ // helper function for _.addTime and _.subtractTime function dateAddRemove(date, _input, adding, val) { var isString = (typeof _input === 'string'), - input = isString ? {} : _input, - ms, d, M, currentDate; - if (isString && val) { - input[_input] = +val; + input, ms, d, M, currentDate; + + if (isString) { + input = moment.duration(+val, _input); + } else { + input = moment.duration(_input); } - ms = (input.ms || input.milliseconds || 0) + - (input.s || input.seconds || 0) * 1e3 + // 1000 - (input.m || input.minutes || 0) * 6e4 + // 1000 * 60 - (input.h || input.hours || 0) * 36e5; // 1000 * 60 * 60 - d = (input.d || input.days || 0) + - (input.w || input.weeks || 0) * 7; - M = (input.M || input.months || 0) + - (input.y || input.years || 0) * 12; + + ms = input.milliseconds + + (input.seconds) * 1e3 + // 1000 + (input.minutes) * 6e4 + // 1000 * 60 + (input.hours) * 36e5; // 1000 * 60 * 60 + d = (input.days) + + (input.weeks) * 7; + M = (input.months) + + (input.years) * 12; if (ms) { date.setTime(+date + ms * adding); }