} else {
duration.milliseconds = input;
}
- } else if (matched) {
- sign = (matched[1] === "-") ? -1 : 1;
+ } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {
+ sign = (match[1] === "-") ? -1 : 1;
duration = {
y: 0,
- d: toInt(matched[DATE]) * sign,
- h: toInt(matched[HOUR]) * sign,
- m: toInt(matched[MINUTE]) * sign,
- s: toInt(matched[SECOND]) * sign,
- ms: toInt(matched[MILLISECOND]) * sign
- d: toInt(match[2]) * sign,
- h: toInt(match[3]) * sign,
- m: toInt(match[4]) * sign,
- s: toInt(match[5]) * sign,
- ms: toInt(match[6]) * sign
++ d: toInt(match[DATE]) * sign,
++ h: toInt(match[HOUR]) * sign,
++ m: toInt(match[MINUTE]) * sign,
++ s: toInt(match[SECOND]) * sign,
++ ms: toInt(match[MILLISECOND]) * sign
+ };
+ } else if (!!(match = isoDurationRegex.exec(input))) {
+ sign = (match[1] === "-") ? -1 : 1;
+ parseIso = function (inp) {
+ // We'd normally use ~~inp for this, but unfortunately it also
+ // converts floats to ints.
+ // inp may be undefined, so careful calling replace on it.
+ var res = inp && parseFloat(inp.replace(',', '.'));
+ // apply sign while we're at it
+ return (isNaN(res) ? 0 : res) * sign;
+ };
+ duration = {
+ y: parseIso(match[2]),
+ M: parseIso(match[3]),
+ d: parseIso(match[4]),
+ h: parseIso(match[5]),
+ m: parseIso(match[6]),
+ s: parseIso(match[7]),
+ w: parseIso(match[8]),
};
}
test.done();
},
+ "invalid date formatting" : function (test) {
+ moment.lang('has-invalid', {
+ invalidDate: 'KHAAAAAAAAAAAN!'
+ });
+
+ test.equal(moment.invalid().format(), "KHAAAAAAAAAAAN!");
+ test.equal(moment.invalid().format('YYYY-MM-DD'), "KHAAAAAAAAAAAN!");
+
++ test.done();
++ },
++
+ "return lang name" : function (test) {
+ test.expect(1);
+
+ var registered = moment.lang('return-this', {});
+
+ test.equal(registered, 'return-this', 'returns the language configured');
+
test.done();
}
};