]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
add support to parse `Do` #1475 1475/head
authorGregor Martynus <gregor@martynus.net>
Tue, 11 Feb 2014 13:48:10 +0000 (14:48 +0100)
committerGregor Martynus <gregor@martynus.net>
Sat, 22 Feb 2014 22:49:29 +0000 (23:49 +0100)
```
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

index 0932e5030f8b8c753eaf614ce45c4066d8a8ee94..0018faebf9fc17fe0486978732e7e5a4ed5197ce 100644 (file)
--- 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
         case 'e':
         case 'E':
             return parseTokenOneOrTwoDigits;
+        case 'Do':
+            return parseTokenOrdinal;
         default :
             a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), "i"));
             return a;
                 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' :