ngx-bootstrap
Version:
Angular Bootstrap
45 lines • 1.36 kB
JavaScript
import { toInt } from '../utils/type-checks';
const ordering = ['year', 'quarter', 'month', 'week', 'day', 'hours', 'minutes', 'seconds', 'milliseconds'];
const ɵ0 = (mem, order) => {
mem[order] = true;
return mem;
};
const orderingHash = ordering.reduce(ɵ0, {});
export function isDurationValid(duration) {
const durationKeys = Object.keys(duration);
if (durationKeys
.some((key) => {
return (key in orderingHash)
&& duration[key] === null
|| isNaN(duration[key]);
})) {
return false;
}
// for (let key in duration) {
// if (!(indexOf.call(ordering, key) !== -1 && (duration[key] == null || !isNaN(duration[key])))) {
// return false;
// }
// }
let unitHasDecimal = false;
for (let i = 0; i < ordering.length; ++i) {
if (duration[ordering[i]]) {
// only allow non-integers for smallest unit
if (unitHasDecimal) {
return false;
}
if (duration[ordering[i]] !== toInt(duration[ordering[i]])) {
unitHasDecimal = true;
}
}
}
return true;
}
export { ɵ0 };
// export function isValid() {
// return this._isValid;
// }
//
// export function createInvalid(): Duration {
// return createDuration(NaN);
// }
//# sourceMappingURL=valid.js.map