Sha256: 4bcb69acbfff7f515874985ec8c2a5083b7f13eae06b644a2d273fec6ce11399

Contents?: true

Size: 1.81 KB

Versions: 41

Compression:

Stored size: 1.81 KB

Contents

import { deprecate } from '../utils/deprecate';
import isArray from '../utils/is-array';
import { createLocal } from '../create/local';
import { createInvalid } from '../create/valid';

export var prototypeMin = deprecate(
    'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
    function () {
        var other = createLocal.apply(null, arguments);
        if (this.isValid() && other.isValid()) {
            return other < this ? this : other;
        } else {
            return createInvalid();
        }
    }
);

export var prototypeMax = deprecate(
    'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
    function () {
        var other = createLocal.apply(null, arguments);
        if (this.isValid() && other.isValid()) {
            return other > this ? this : other;
        } else {
            return createInvalid();
        }
    }
);

// Pick a moment m from moments so that m[fn](other) is true for all
// other. This relies on the function fn to be transitive.
//
// moments should either be an array of moment objects or an array, whose
// first element is an array of moment objects.
function pickBy(fn, moments) {
    var res, i;
    if (moments.length === 1 && isArray(moments[0])) {
        moments = moments[0];
    }
    if (!moments.length) {
        return createLocal();
    }
    res = moments[0];
    for (i = 1; i < moments.length; ++i) {
        if (!moments[i].isValid() || moments[i][fn](res)) {
            res = moments[i];
        }
    }
    return res;
}

// TODO: Use [].sort instead?
export function min () {
    var args = [].slice.call(arguments, 0);

    return pickBy('isBefore', args);
}

export function max () {
    var args = [].slice.call(arguments, 0);

    return pickBy('isAfter', args);
}

Version data entries

41 entries across 40 versions & 9 rubygems

Version Path
card-1.100.0 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.99.6 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.99.5 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.99.4 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.99.3 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.99.2 mod/date/vendor/moment/src/lib/moment/min-max.js
ilog-0.4.1 node_modules/moment/src/lib/moment/min-max.js
ilog-0.4.0 node_modules/moment/src/lib/moment/min-max.js
ilog-0.3.3 node_modules/moment/src/lib/moment/min-max.js
card-1.99.1 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.99.0 mod/date/vendor/moment/src/lib/moment/min-max.js
jester-data-8.0.0 node_modules/moment/src/lib/moment/min-max.js
ezii-os-5.2.1 node_modules/moment/src/lib/moment/min-max.js
ezii-os-2.0.1 node_modules/moment/src/lib/moment/min-max.js
card-1.98.3 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.98.2 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.98.1 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.98.0 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.97.0.1 mod/date/vendor/moment/src/lib/moment/min-max.js
card-1.97.0 mod/date/vendor/moment/src/lib/moment/min-max.js