MCPcopy Index your code
hub / github.com/csev/py4e / create__createDuration

Function create__createDuration

code/gmane/Chart.bundle.js:3281–3340  ·  view source on GitHub ↗
(input, key)

Source from the content-addressed store, hash-verified

3279 var create__isoRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;
3280
3281 function create__createDuration (input, key) {
3282 var duration = input,
3283 // matching against regexp is expensive, do it on demand
3284 match = null,
3285 sign,
3286 ret,
3287 diffRes;
3288
3289 if (isDuration(input)) {
3290 duration = {
3291 ms : input._milliseconds,
3292 d : input._days,
3293 M : input._months
3294 };
3295 } else if (typeof input === 'number') {
3296 duration = {};
3297 if (key) {
3298 duration[key] = input;
3299 } else {
3300 duration.milliseconds = input;
3301 }
3302 } else if (!!(match = aspNetRegex.exec(input))) {
3303 sign = (match[1] === '-') ? -1 : 1;
3304 duration = {
3305 y : 0,
3306 d : toInt(match[DATE]) * sign,
3307 h : toInt(match[HOUR]) * sign,
3308 m : toInt(match[MINUTE]) * sign,
3309 s : toInt(match[SECOND]) * sign,
3310 ms : toInt(match[MILLISECOND]) * sign
3311 };
3312 } else if (!!(match = create__isoRegex.exec(input))) {
3313 sign = (match[1] === '-') ? -1 : 1;
3314 duration = {
3315 y : parseIso(match[2], sign),
3316 M : parseIso(match[3], sign),
3317 d : parseIso(match[4], sign),
3318 h : parseIso(match[5], sign),
3319 m : parseIso(match[6], sign),
3320 s : parseIso(match[7], sign),
3321 w : parseIso(match[8], sign)
3322 };
3323 } else if (duration == null) {// checks for null or undefined
3324 duration = {};
3325 } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
3326 diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to));
3327
3328 duration = {};
3329 duration.ms = diffRes.milliseconds;
3330 duration.M = diffRes.months;
3331 }
3332
3333 ret = new Duration(duration);
3334
3335 if (isDuration(input) && hasOwnProp(input, '_locale')) {
3336 ret._locale = input._locale;
3337 }
3338

Callers 6

getSetOffsetFunction · 0.85
createAdderFunction · 0.85
fromFunction · 0.85
toFunction · 0.85

Calls 6

isDurationFunction · 0.85
toIntFunction · 0.85
parseIsoFunction · 0.85
momentsDifferenceFunction · 0.85
local__createLocalFunction · 0.85
hasOwnPropFunction · 0.85

Tested by

no test coverage detected