]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
AspNET duration regex now correctly handles days 910/head
authorIskren Chernev <iskren.chernev@gmail.com>
Sun, 14 Jul 2013 04:16:41 +0000 (21:16 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Sat, 20 Jul 2013 16:31:31 +0000 (14:31 -0200)
Days are now completely optional and won't steal digits from the hours.

moment.js
test/moment/duration.js

index bdc4c425b28d82ff8b1db61390876c833a93db51..f02c661097efd56f04e9be61fd156f83f72b99f7 100644 (file)
--- a/moment.js
+++ b/moment.js
@@ -21,7 +21,7 @@
 
         // ASP.NET json date format regex
         aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
-        aspNetTimeSpanJsonRegex = /(\-)?(\d*)?\.?(\d+)\:(\d+)\:(\d+)\.?(\d{3})?/,
+        aspNetTimeSpanJsonRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)\:(\d+)\.?(\d{3})?/,
 
         // format tokens
         formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/g,
index 1aaee7d23d141f1db068c450c9396f41552315fa..29feb9269ae8c3218d1c7310ef68ac99cb86c7d4 100644 (file)
@@ -138,13 +138,19 @@ exports.duration = {
     },
 
     "instatiation from serialized C# TimeSpan without days" : function (test) {
-        test.expect(6);
+        test.expect(10);
         test.equal(moment.duration("01:02:03.9999999").years(), 0, "0 years");
         test.equal(moment.duration("01:02:03.9999999").days(), 0, "0 days");
         test.equal(moment.duration("01:02:03.9999999").hours(), 1, "1 hour");
         test.equal(moment.duration("01:02:03.9999999").minutes(), 2, "2 minutes");
         test.equal(moment.duration("01:02:03.9999999").seconds(), 3, "3 seconds");
         test.equal(moment.duration("01:02:03.9999999").milliseconds(), 999, "999 milliseconds");
+
+        test.equal(moment.duration("23:59:59.9999999").days(), 0, "0 days");
+        test.equal(moment.duration("23:59:59.9999999").hours(), 23, "23 hours");
+
+        test.equal(moment.duration("500:59:59.9999999").days(), 20, "500 hours overflows to 20 days");
+        test.equal(moment.duration("500:59:59.9999999").hours(), 20, "500 hours overflows to 20 hours");
         test.done();
     },