]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Backwards compatibility with changing moment.months and other lang properties
authorTim Wood <timwood@timrwood.(none)>
Thu, 5 Jul 2012 17:46:31 +0000 (10:46 -0700)
committerTim Wood <timwood@timrwood.(none)>
Thu, 5 Jul 2012 17:46:31 +0000 (10:46 -0700)
#332 #334

moment.js
test/moment/lang.js

index f7d472a23d49ad58a2a0368695e070270d7fce73..c959ab31debf2f52053d38f3f31e6ef8bde6d7a8 100644 (file)
--- a/moment.js
+++ b/moment.js
     function getLangDefinition(m) {
         var langKey = (typeof m === 'string') && m ||
                       m && m._lang ||
-                      currentLanguage;
+                      null;
 
-        return languages[langKey] || loadLang(langKey);
+        return langKey ? (languages[langKey] || loadLang(langKey)) : moment;
     }
 
 
             for (i = 0; i < langConfigProperties.length; i++) {
                 moment[langConfigProperties[i]] = languages[key][langConfigProperties[i]];
             }
+            moment.monthsParse = languages[key].monthsParse;
             currentLanguage = key;
         }
     };
index 09afb5ed5f2028275e2794ea7fa6b4e363643603..b4823f1972512705e7c203d64c60f0b3a3ee9b14 100644 (file)
@@ -141,6 +141,57 @@ exports.lang = {
         test.equal(moment([2011, 0, 1]).format('dd ddd dddd MMM MMMM'), 'date date date date date', 'format month name function should be able to access the moment object');
         test.equal(moment([2011, 0, 2]).format('dd ddd dddd MMM MMMM'), 'default default default default default', 'format month name function should be able to access the moment object');
 
+        test.done();
+    },
+
+    // the following tests should be removed after the 2.0.0 release as they will be deprecated
+    "lang accessors on the global object should exist < 2.0.0" : function(test) {
+        moment.lang('en');
+
+        var a = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|');
+        var i;
+
+        test.expect(a.length);
+
+        for (i = 0; i < a.length; i++) {
+            test.ok(moment[a[i]], "moment." + a[i] + " should exist");
+        }
+
+        test.done();
+    },
+
+    // the following tests should be removed after the 2.0.0 release as they will be deprecated
+    "lang accessors on the global object should change < 2.0.0" : function(test) {
+        moment.lang('en');
+
+        var a = 'months|monthsShort|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal'.split('|');
+        var i;
+        var en = {};
+
+        test.expect(a.length);
+
+        for (i = 0; i < a.length; i++) {
+            en[a[i]] = moment[a[i]];
+        }
+
+        moment.lang('fr');
+
+        for (i = 0; i < a.length; i++) {
+            test.notDeepEqual(en[a[i]], moment[a[i]], "the " + a[i] + " lang data should change on the global object");
+        }
+
+        test.done();
+    },
+
+    "manip lang accessors on the global object < 2.0.0" : function(test) {
+        test.expect(1);
+        moment.lang('en');
+
+        moment.months = ["test"];
+        test.equal(moment([2011, 0]).format('MMMM'), "test", "Should be able to manipulate the objects on the global object");
+
+        moment.lang('en');
+
         test.done();
     }
 };