From: Iskren Chernev Date: Thu, 1 May 2014 17:23:13 +0000 (-0700) Subject: Implement moment.min and moment.max X-Git-Tag: 2.7.0~22^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a289b8eb3c451b4cce9213864ee46ab37c00aef;p=thirdparty%2Fmoment.git Implement moment.min and moment.max --- diff --git a/moment.js b/moment.js index 0c6da7323..acf57da09 100644 --- a/moment.js +++ b/moment.js @@ -1641,6 +1641,40 @@ 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; @@ -2069,7 +2103,7 @@ } ), - max: deprecated( + max: deprecate( "moment().max is deprecated, use moment.max instead", function (other) { other = moment.apply(null, arguments);