(input, key)
| 3524 | /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/; |
| 3525 | |
| 3526 | function createDuration(input, key) { |
| 3527 | var duration = input, |
| 3528 | // matching against regexp is expensive, do it on demand |
| 3529 | match = null, |
| 3530 | sign, |
| 3531 | ret, |
| 3532 | diffRes; |
| 3533 | |
| 3534 | if (isDuration(input)) { |
| 3535 | duration = { |
| 3536 | ms: input._milliseconds, |
| 3537 | d: input._days, |
| 3538 | M: input._months, |
| 3539 | }; |
| 3540 | } else if (isNumber(input) || !isNaN(+input)) { |
| 3541 | duration = {}; |
| 3542 | if (key) { |
| 3543 | duration[key] = +input; |
| 3544 | } else { |
| 3545 | duration.milliseconds = +input; |
| 3546 | } |
| 3547 | } else if ((match = aspNetRegex.exec(input))) { |
| 3548 | sign = match[1] === '-' ? -1 : 1; |
| 3549 | duration = { |
| 3550 | y: 0, |
| 3551 | d: toInt(match[DATE]) * sign, |
| 3552 | h: toInt(match[HOUR]) * sign, |
| 3553 | m: toInt(match[MINUTE]) * sign, |
| 3554 | s: toInt(match[SECOND]) * sign, |
| 3555 | ms: toInt(absRound(match[MILLISECOND] * 1000)) * sign, // the millisecond decimal point is included in the match |
| 3556 | }; |
| 3557 | } else if ((match = isoRegex.exec(input))) { |
| 3558 | sign = match[1] === '-' ? -1 : 1; |
| 3559 | duration = { |
| 3560 | y: parseIso(match[2], sign), |
| 3561 | M: parseIso(match[3], sign), |
| 3562 | w: parseIso(match[4], sign), |
| 3563 | d: parseIso(match[5], sign), |
| 3564 | h: parseIso(match[6], sign), |
| 3565 | m: parseIso(match[7], sign), |
| 3566 | s: parseIso(match[8], sign), |
| 3567 | }; |
| 3568 | } else if (duration == null) { |
| 3569 | // checks for null or undefined |
| 3570 | duration = {}; |
| 3571 | } else if ( |
| 3572 | typeof duration === 'object' && |
| 3573 | ('from' in duration || 'to' in duration) |
| 3574 | ) { |
| 3575 | diffRes = momentsDifference( |
| 3576 | createLocal(duration.from), |
| 3577 | createLocal(duration.to) |
| 3578 | ); |
| 3579 | |
| 3580 | duration = {}; |
| 3581 | duration.ms = diffRes.milliseconds; |
| 3582 | duration.M = diffRes.months; |
| 3583 | } |
no test coverage detected
searching dependent graphs…