Skip to content

Commit

Permalink
Working on adding MMM and MMMM parsing tokens
Browse files Browse the repository at this point in the history
Note: unfinished commit, moving to another machine...
  • Loading branch information
timrwood committed Dec 28, 2011
1 parent 70a8b7d commit 3f09060
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
32 changes: 32 additions & 0 deletions lang/test/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,38 @@

module("lang:en");

test("parse", 96, function() {
moment.lang('en');
var tests = [
['Jan', 'January'],
['Feb', 'February'],
['Mar', 'March'],
['Apr', 'April'],
['May', 'May'],
['Jun', 'June'],
['Jul', 'July'],
['Aug', 'August'],
['Sep', 'September'],
['Oct', 'October'],
['Nov', 'November'],
['Dec', 'December']
];
var i;
function equalTest(input, mmm, i) {
equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
}
for (i = 0; i < 12; i++) {
equalTest(tests[i][0], 'MMM', i);
equalTest(tests[i][1], 'MMM', i);
equalTest(tests[i][0], 'MMMM', i);
equalTest(tests[i][1], 'MMMM', i);
equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
}
});

test("format", 18, function() {
moment.lang('en');
var a = [
Expand Down
22 changes: 20 additions & 2 deletions moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
round = Math.round,
languages = {},
hasModule = (typeof module !== 'undefined'),
paramsToParse = 'months|monthsShort|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|'),
paramsToParse = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|'),
i,
VERSION = "1.2.0",
shortcuts = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|');
Expand Down Expand Up @@ -202,11 +202,12 @@
timezoneHours = 0,
timezoneMinutes = 0,
isUsingUTC = false,
tokenCharacters = /(\\)?(MM?|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?)/g,
tokenCharacters = /(\\)?(MM?M?M?|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?)/g,
inputCharacters = /(\\)?([0-9]+|am|pm|([\+\-]\d\d:?\d\d))/gi,
timezoneParseRegex = /([\+\-]|\d\d)/gi,
inputParts = string.match(inputCharacters),
formatParts = format.match(tokenCharacters),
monthRegex = moment.monthsParse,
i,
isPm;

Expand All @@ -220,6 +221,17 @@
case 'MM' :
inArray[1] = ~~input - 1;
break;
case 'MMM' :
// fall through to MMMM
case 'MMMM' :
for (a = 0; a < 12; a++) {
if (monthRegex[i].test(input)) {
console.log('found it');
inArray[1] = a;
break;
}
}
break;
// DAY OF MONTH
case 'D' :
// fall through to DDDD
Expand Down Expand Up @@ -377,6 +389,12 @@
var i, param, req;
if (values) {
languages[key] = values;
if (!values.monthsParse) {
languages[key].monthsParse = [];
for (i = 0; i < 12; i++) {
languages[key].monthsParse[i] = new RegExp(values.months[i] + '|' + values.monthsShort[i], 'i');
}
}
}
if (languages[key]) {
for (i = 0; i < paramsToParse.length; i++) {
Expand Down

0 comments on commit 3f09060

Please sign in to comment.