]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
simplifying
authorIsaac Cambron <isaac@isaaccambron.com>
Mon, 16 Sep 2013 03:14:11 +0000 (23:14 -0400)
committerIsaac Cambron <isaac@isaaccambron.com>
Mon, 16 Sep 2013 03:14:11 +0000 (23:14 -0400)
moment.js

index 024cc0bd0075399f8637ebf8a0096a15a49d5974..e35fff4473180d4a147a922f4b2c00d7ee1fcb20 100644 (file)
--- a/moment.js
+++ b/moment.js
             X    : function () {
                 return this.unix();
             }
-        };
+        },
+
+        lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'];
 
     function padToken(func, count) {
         return function (a) {
         return units ? unitAliases[units] || units.toLowerCase().replace(/(.)s$/, '$1') : units;
     }
 
-    function listLocal(field, format) {
-        var i, m, str, method, count, setter,
-            months = [];
+    function makeList(field) {
+        var count, setter;
 
-        if (field.match(/^week/)) {
+        if (field.indexOf('week') === 0) {
             count = 7;
             setter = 'day';
         }
-        else if (field.match(/^month/)) {
+        else if (field.indexOf('month') === 0) {
             count = 12;
             setter = 'month';
         }
         else {
-            return [];
+            return;
         }
 
-        for (i = 0; i < count; i++) {
-            m = moment().utc().set(setter, i);
-            method = moment.fn._lang[field] || Language.prototype[field];
-            str = method.call(moment.fn._lang, m, format || '');
-            months.push(str);
-        }
+        moment[field] = function (format) {
+            var i, m, str,
+                method = moment.fn._lang[field] || Language.prototype[field],
+                results = [];
 
-        return months;
+            for (i = 0; i < count; i++) {
+                m = moment().utc().set(setter, i);
+                str = method.call(moment.fn._lang, m, format || '');
+                results.push(str);
+            }
+
+            return results;
+        };
     }
 
     /************************************
         return getLangDefinition(key);
     };
 
-    moment.months = function (format) {
-        return listLocal('months', format);
-    };
-
-    moment.monthsShort = function (format) {
-        return listLocal('monthsShort', format);
-    };
-
-    moment.weekdays = function () {
-        return listLocal('weekdays');
-    };
-
-    moment.weekdaysShort = function () {
-        return listLocal('weekdaysShort');
-    };
-
-    moment.weekdaysMin = function () {
-        return listLocal('weekdaysMin');
-    };
-
     // compare moment object
     moment.isMoment = function (obj) {
         return obj instanceof Moment;
         return obj instanceof Duration;
     };
 
+    for (i in lists) {
+        makeList(lists[i]);
+    }
 
     /************************************
         Moment Prototype