ngx-bootstrap
Version:
Native Angular Bootstrap Components
58 lines • 4.87 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// 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.
import { isArray, isDateValid } from '../utils/type-checks';
import { isAfter, isBefore } from '../utils/date-compare';
/**
* @param {?} fn
* @param {?} dates
* @return {?}
*/
function pickBy(fn, dates) {
/** @type {?} */
let _dates;
/** @type {?} */
const _firstArg = dates[0];
if (isArray(_firstArg) && dates.length === 1) {
_dates = _firstArg;
}
else if (isArray(dates)) {
_dates = dates;
}
if (!_dates || !_dates.length) {
return new Date();
}
/** @type {?} */
let res = _dates[0];
for (let i = 1; i < _dates.length; ++i) {
// if (!moments[i].isValid() || moments[i][fn](res)) {
if (!isDateValid(_dates[i]) || fn.call(null, _dates[i], res)) {
res = _dates[i];
}
}
return res;
}
// TODO: Use [].sort instead?
/**
* @param {...?} args
* @return {?}
*/
export function min(...args) {
// const args = [].slice.call(arguments, 0);
return pickBy(isBefore, args);
}
/**
* @param {...?} args
* @return {?}
*/
export function max(...args) {
// const args = [].slice.call(arguments, 0);
return pickBy(isAfter, args);
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWluLW1heC5qcyIsInNvdXJjZVJvb3QiOiJuZzovL25neC1ib290c3RyYXAvY2hyb25vcy8iLCJzb3VyY2VzIjpbIm1vbWVudC9taW4tbWF4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUtBLE9BQU8sRUFBRSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDNUQsT0FBTyxFQUFFLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQzs7Ozs7O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