]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
adding ability to set the parse language 574/head
authorTim Wood <washwithcare@gmail.com>
Fri, 11 Jan 2013 18:52:52 +0000 (10:52 -0800)
committerTim Wood <washwithcare@gmail.com>
Fri, 11 Jan 2013 18:52:52 +0000 (10:52 -0800)
moment.js
test/moment/create.js

index 1d9cbcf842c92e17267f8c4085b551691c0810b1..32b17ec1827e4e64acea0907a7cadb3f181a7035 100644 (file)
--- a/moment.js
+++ b/moment.js
             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;
         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
         });
index 2be29b53d34c1e7c1df76bc434d36dc90f3586a1..29bc59f8bc2d2a896a1617ebfe881fa2472a99fc 100644 (file)
@@ -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();
     }
 };