MCPcopy Index your code
hub / github.com/feiyu563/PrometheusAlert / createDuration

Function createDuration

static/plugins/chart.js/Chart.bundle.js:17735–17794  ·  view source on GitHub ↗
(input, key)

Source from the content-addressed store, hash-verified

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

Callers 8

createInvalid$1Function · 0.85
getSetOffsetFunction · 0.85
createAdderFunction · 0.85
fromFunction · 0.85
toFunction · 0.85
addSubtract$1Function · 0.85
clone$1Function · 0.85
relativeTime$1Function · 0.85

Calls 8

isDurationFunction · 0.85
toIntFunction · 0.85
absRoundFunction · 0.85
parseIsoFunction · 0.85
momentsDifferenceFunction · 0.85
createLocalFunction · 0.85
hasOwnPropFunction · 0.85
isNumberFunction · 0.70

Tested by

no test coverage detected