From: Tim Wood Date: Fri, 11 Jan 2013 18:52:52 +0000 (-0800) Subject: adding ability to set the parse language X-Git-Tag: 2.0.0~18^2~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F574%2Fhead;p=thirdparty%2Fmoment.git adding ability to set the parse language --- diff --git a/moment.js b/moment.js index 1d9cbcf84..32b17ec18 100644 --- a/moment.js +++ b/moment.js @@ -608,7 +608,7 @@ break; case 'MMM' : // fall through to MMMM case 'MMMM' : - a = getLangDefinition().monthsParse(input); + a = getLangDefinition(config._l).monthsParse(input); // if we didn't find a month name, mark the date as invalid. if (a != null) { datePartArray[1] = a; @@ -912,19 +912,21 @@ return new Moment(config); } - moment = function (input, format) { + moment = function (input, format, lang) { return makeMoment({ _i : input, _f : format, + _l : lang, _isUTC : false }); }; // creating with utc - moment.utc = function (input, format) { + moment.utc = function (input, format, lang) { return makeMoment({ _useUTC : true, _isUTC : true, + _l : lang, _i : input, _f : format }); diff --git a/test/moment/create.js b/test/moment/create.js index 2be29b53d..29bc59f8b 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -350,6 +350,25 @@ exports.create = { test.expect(2); test.equal(moment("-1000-01-01", "YYYYY-MM-DD").toDate().getFullYear(), -1000, "parse BC 1,001"); test.equal(moment.utc("-1000-01-01", "YYYYY-MM-DD").toDate().getUTCFullYear(), -1000, "parse utc BC 1,001"); + test.done(); + }, + + "parsing into a language" : function (test) { + test.expect(2); + + moment.lang('parselang', { + months : "one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve".split('_'), + monthsShort : "one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve".split("_") + }); + + moment.lang('en'); + + test.equal(moment('2012 seven', 'YYYY MMM', 'parselang').month(), 6, "should be able to parse in a specific language"); + + moment.lang('parselang'); + + test.equal(moment('2012 july', 'YYYY MMM', 'en').month(), 6, "should be able to parse in a specific language"); + test.done(); } };