import { createLocal } from '../create/local';
// ASP.NET json date format regex
-var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?\d*)?$/;
+var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
// from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
// somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
sign = (match[1] === '-') ? -1 : 1;
duration = {
y : 0,
- 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
+ d : toInt(match[DATE]) * sign,
+ h : toInt(match[HOUR]) * sign,
+ m : toInt(match[MINUTE]) * sign,
+ s : toInt(match[SECOND]) * sign,
+ ms : toInt(match[MILLISECOND] * 1000) * sign // the millisecond decimal point is included in the match
};
} else if (!!(match = isoRegex.exec(input))) {
sign = (match[1] === '-') ? -1 : 1;
assert.equal(moment.duration('1.02:03:04').milliseconds(), 0, '0 milliseconds');
});
+test('instantiation from serialized C# TimeSpan with low millisecond precision', function (assert) {
+ assert.equal(moment.duration('00:00:15.72').years(), 0, '0 years');
+ assert.equal(moment.duration('00:00:15.72').days(), 0, '0 days');
+ assert.equal(moment.duration('00:00:15.72').hours(), 0, '0 hours');
+ assert.equal(moment.duration('00:00:15.72').minutes(), 0, '0 minutes');
+ assert.equal(moment.duration('00:00:15.72').seconds(), 15, '15 seconds');
+ assert.equal(moment.duration('00:00:15.72').milliseconds(), 720, '720 milliseconds');
+
+ assert.equal(moment.duration('00:00:15.7').milliseconds(), 700, '700 milliseconds');
+
+ assert.equal(moment.duration('00:00:15.').milliseconds(), 0, '0 milliseconds');
+});
+
test('instatiation from serialized C# TimeSpan maxValue', function (assert) {
var d = moment.duration('10675199.02:48:05.4775807');