PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/moment/src/lib/moment/min-max.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 63 lines | 50 code | 7 blank | 6 comment | 12 complexity | 6eb12e940d8616cf7e7407f2d9fa48b0 MD5 | raw file
 1import { deprecate } from '../utils/deprecate';
 2import isArray from '../utils/is-array';
 3import { createLocal } from '../create/local';
 4import { createInvalid } from '../create/valid';
 5
 6export var prototypeMin = deprecate(
 7    'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
 8    function () {
 9        var other = createLocal.apply(null, arguments);
10        if (this.isValid() && other.isValid()) {
11            return other < this ? this : other;
12        } else {
13            return createInvalid();
14        }
15    }
16);
17
18export var prototypeMax = deprecate(
19    'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
20    function () {
21        var other = createLocal.apply(null, arguments);
22        if (this.isValid() && other.isValid()) {
23            return other > this ? this : other;
24        } else {
25            return createInvalid();
26        }
27    }
28);
29
30// Pick a moment m from moments so that m[fn](other) is true for all
31// other. This relies on the function fn to be transitive.
32//
33// moments should either be an array of moment objects or an array, whose
34// first element is an array of moment objects.
35function pickBy(fn, moments) {
36    var res, i;
37    if (moments.length === 1 && isArray(moments[0])) {
38        moments = moments[0];
39    }
40    if (!moments.length) {
41        return createLocal();
42    }
43    res = moments[0];
44    for (i = 1; i < moments.length; ++i) {
45        if (!moments[i].isValid() || moments[i][fn](res)) {
46            res = moments[i];
47        }
48    }
49    return res;
50}
51
52// TODO: Use [].sort instead?
53export function min () {
54    var args = [].slice.call(arguments, 0);
55
56    return pickBy('isBefore', args);
57}
58
59export function max () {
60    var args = [].slice.call(arguments, 0);
61
62    return pickBy('isAfter', args);
63}