From 742ba1e308d785eda289c1741587709845bb2291 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Tue, 11 Feb 2014 14:48:10 +0100 Subject: [PATCH] add support to parse `Do` #1475 ``` moment('May 6th', 'MMMM Do').format('MMMM Do') // before => May 1st // after => May 6th ``` To assure that the patch is working as expected, a temporary test file has been added. It can still be found at https://gist.github.com/gr2m/3c56d1ff91bec49f547c --- moment.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/moment.js b/moment.js index 0932e5030f..0018faebf9 100644 --- a/moment.js +++ b/moment.js @@ -65,6 +65,7 @@ parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z parseTokenT = /T/i, // T (ISO separator) parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123 + parseTokenOrdinal = /\d{1,2}/, //strict parsing regexes parseTokenOneDigit = /\d/, // 0 - 9 @@ -1023,6 +1024,8 @@ case 'e': case 'E': return parseTokenOneOrTwoDigits; + case 'Do': + return parseTokenOrdinal; default : a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), "i")); return a; @@ -1068,6 +1071,11 @@ datePartArray[DATE] = toInt(input); } break; + case 'Do' : + if (input != null) { + datePartArray[DATE] = toInt(parseInt(input, 10)); + } + break; // DAY OF YEAR case 'DDD' : // fall through to DDDD case 'DDDD' :