]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Enable 'd hh:mm:ss.sss' format for durations
authorIskren Chernev <iskren.chernev@gmail.com>
Mon, 9 Nov 2015 06:35:36 +0000 (22:35 -0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 9 Dec 2015 06:48:07 +0000 (22:48 -0800)
Fix #2342

src/lib/duration/create.js
src/test/moment/duration.js

index 9d1ea4eb4043b3fd06fd080905a681a70cb3680b..a79feea319cf35cc47794a625787bf257fbde16e 100644 (file)
@@ -6,7 +6,7 @@ import { cloneWithOffset } from '../units/offset';
 import { createLocal } from '../create/local';
 
 // ASP.NET json date format regex
-var aspNetRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/;
+var aspNetRegex = /(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/;
 
 // 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
index bb9d066ac56440b732a9dc4f94632735375950d9..809a64846f758e6a14a6e2127edcd0264eb926c1 100644 (file)
@@ -180,6 +180,13 @@ test('instatiation from serialized C# TimeSpan with days', function (assert) {
     assert.equal(moment.duration('1.02:03:04.9999999').minutes(), 3, '3 minutes');
     assert.equal(moment.duration('1.02:03:04.9999999').seconds(), 4, '4 seconds');
     assert.equal(moment.duration('1.02:03:04.9999999').milliseconds(), 999, '999 milliseconds');
+
+    assert.equal(moment.duration('1 02:03:04.9999999').years(), 0, '0 years');
+    assert.equal(moment.duration('1 02:03:04.9999999').days(), 1, '1 day');
+    assert.equal(moment.duration('1 02:03:04.9999999').hours(), 2, '2 hours');
+    assert.equal(moment.duration('1 02:03:04.9999999').minutes(), 3, '3 minutes');
+    assert.equal(moment.duration('1 02:03:04.9999999').seconds(), 4, '4 seconds');
+    assert.equal(moment.duration('1 02:03:04.9999999').milliseconds(), 999, '999 milliseconds');
 });
 
 test('instatiation from serialized C# TimeSpan without days', function (assert) {