From 58c2ac01874516da51601a6f3455b67e2ecb7645 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Sat, 13 Jul 2013 21:16:41 -0700 Subject: [PATCH] AspNET duration regex now correctly handles days Days are now completely optional and won't steal digits from the hours. --- moment.js | 2 +- test/moment/duration.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/moment.js b/moment.js index bdc4c425b..f02c66109 100644 --- 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, diff --git a/test/moment/duration.js b/test/moment/duration.js index 1aaee7d23..29feb9269 100644 --- a/test/moment/duration.js +++ b/test/moment/duration.js @@ -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(); }, -- 2.47.2