]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Allowing you to set values on a language after it has been loaded #580
authorTim Wood <washwithcare@gmail.com>
Tue, 15 Jan 2013 19:45:08 +0000 (11:45 -0800)
committerTim Wood <washwithcare@gmail.com>
Tue, 15 Jan 2013 19:45:08 +0000 (11:45 -0800)
moment.js
test/moment/lang.js

index 414fafdd3cccf9a9eafaf79aaaa5e0a5220def53..70d6772a5fe83809abbcc2a124e6c6110fc7c3c2 100644 (file)
--- a/moment.js
+++ b/moment.js
         Constructors
     ************************************/
 
-    function Language(config) {
-        var prop, i;
-        for (i in config) {
-            prop = config[i];
-            if (typeof prop === 'function') {
-                this[i] = prop;
-            } else {
-                this['_' + i] = prop;
-            }
-        }
+    function Language() {
+
     }
 
     // Moment prototype object
 
 
     Language.prototype = {
+        set : function (config) {
+            var prop, i;
+            for (i in config) {
+                prop = config[i];
+                if (typeof prop === 'function') {
+                    this[i] = prop;
+                } else {
+                    this['_' + i] = prop;
+                }
+            }
+        },
+
         _months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
         months : function (m) {
             return this._months[m.month()];
     // this function also returns the language values.
     function loadLang(key, values) {
         values.abbr = key;
-        languages[key] = new Language(values);
+        if (!languages[key]) {
+            languages[key] = new Language();
+        }
+        languages[key].set(values);
         return languages[key];
     }
 
index a5d7328fd86e4c140f7f55da2b3682957c80a73a..8f8fb9513acab8198f32ef602963a05e4bdd8693 100644 (file)
@@ -180,56 +180,21 @@ exports.lang = {
         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");
-        }
+    "changing parts of a language config" : function (test) {
+        test.expect(2);
 
-        test.done();
-    },
+        moment.lang('partial-lang', {
+            months : 'a b c d e f g h i j k l'.split(' ')
+        });
 
-    "manip lang accessors on the global object < 2.0.0" : function (test) {
-        test.expect(1);
-        moment.lang('en');
+        test.equal(moment([2011, 0, 1]).format('MMMM'), 'a', 'should be able to set language values when creating the language');
 
-        moment.months = ["test"];
-        test.equal(moment([2011, 0]).format('MMMM'), "test", "Should be able to manipulate the objects on the global object");
+        moment.lang('partial-lang', {
+            monthsShort : 'A B C D E F G H I J K L'.split(' ')
+        });
 
-        moment.lang('en');
+        test.equal(moment([2011, 0, 1]).format('MMMM MMM'), 'a A', 'should be able to set language values after creating the language');
 
         test.done();
     }
-*/
 };