]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Implement moment.min and moment.max
authorIskren Chernev <iskren.chernev@gmail.com>
Thu, 1 May 2014 17:23:13 +0000 (10:23 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Thu, 1 May 2014 17:23:13 +0000 (10:23 -0700)
moment.js

index 0c6da73234d227efa31382e55b5b1ac144a5a175..acf57da09d9bb5bac3fad360f10c919cd05cb1ec 100644 (file)
--- a/moment.js
+++ b/moment.js
         config._d = new Date(config._i);
     });
 
+    function _pickBy(key, moments) {
+        var res, i;
+        if (!moments.length) {
+            return moment();
+        }
+        res = moments[0];
+        for (i = 1; i < moments.length; ++i) {
+            if (moments[i][key](res)) {
+                res = moments[i];
+            }
+        }
+        return res;
+    }
+
+    moment.min = function () {
+        var args = [].slice.call(arguments, 0);
+
+        if (args.length === 1 && isArray(args[0])) {
+            return _pickBy('isBefore', args[0]);
+        } else {
+            return _pickBy('isBefore', args);
+        }
+    },
+
+    moment.max = function () {
+        var args = [].slice.call(arguments, 0);
+
+        if (args.length === 1 && isArray(args[0])) {
+            return _pickBy('isAfter', args[0]);
+        } else {
+            return _pickBy('isAfter', args);
+        }
+    },
+
     // creating with utc
     moment.utc = function (input, format, lang, strict) {
         var c;
                  }
          ),
 
-        max: deprecated(
+        max: deprecate(
                 "moment().max is deprecated, use moment.max instead",
                 function (other) {
                     other = moment.apply(null, arguments);