(input, key)
| 17733 | var isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/; |
| 17734 | |
| 17735 | function createDuration (input, key) { |
| 17736 | var duration = input, |
| 17737 | // matching against regexp is expensive, do it on demand |
| 17738 | match = null, |
| 17739 | sign, |
| 17740 | ret, |
| 17741 | diffRes; |
| 17742 | |
| 17743 | if (isDuration(input)) { |
| 17744 | duration = { |
| 17745 | ms : input._milliseconds, |
| 17746 | d : input._days, |
| 17747 | M : input._months |
| 17748 | }; |
| 17749 | } else if (isNumber(input)) { |
| 17750 | duration = {}; |
| 17751 | if (key) { |
| 17752 | duration[key] = input; |
| 17753 | } else { |
| 17754 | duration.milliseconds = input; |
| 17755 | } |
| 17756 | } else if (!!(match = aspNetRegex.exec(input))) { |
| 17757 | sign = (match[1] === '-') ? -1 : 1; |
| 17758 | duration = { |
| 17759 | y : 0, |
| 17760 | d : toInt(match[DATE]) * sign, |
| 17761 | h : toInt(match[HOUR]) * sign, |
| 17762 | m : toInt(match[MINUTE]) * sign, |
| 17763 | s : toInt(match[SECOND]) * sign, |
| 17764 | ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match |
| 17765 | }; |
| 17766 | } else if (!!(match = isoRegex.exec(input))) { |
| 17767 | sign = (match[1] === '-') ? -1 : 1; |
| 17768 | duration = { |
| 17769 | y : parseIso(match[2], sign), |
| 17770 | M : parseIso(match[3], sign), |
| 17771 | w : parseIso(match[4], sign), |
| 17772 | d : parseIso(match[5], sign), |
| 17773 | h : parseIso(match[6], sign), |
| 17774 | m : parseIso(match[7], sign), |
| 17775 | s : parseIso(match[8], sign) |
| 17776 | }; |
| 17777 | } else if (duration == null) {// checks for null or undefined |
| 17778 | duration = {}; |
| 17779 | } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) { |
| 17780 | diffRes = momentsDifference(createLocal(duration.from), createLocal(duration.to)); |
| 17781 | |
| 17782 | duration = {}; |
| 17783 | duration.ms = diffRes.milliseconds; |
| 17784 | duration.M = diffRes.months; |
| 17785 | } |
| 17786 | |
| 17787 | ret = new Duration(duration); |
| 17788 | |
| 17789 | if (isDuration(input) && hasOwnProp(input, '_locale')) { |
| 17790 | ret._locale = input._locale; |
| 17791 | } |
| 17792 |
no test coverage detected