playwright-fluent
Version:
Fluent API around playwright
30 lines (29 loc) • 868 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.shouldUpdate = exports.toDays = void 0;
function toDays(policy) {
switch (policy) {
case '1/d':
return 1;
case '1/w':
return 7;
case '1/m':
return 30;
default:
throw new Error(`Unknown update policy '${policy}'. Valid policies are: '1/d', '1/w', '1/m', 'always', 'never'`);
}
}
exports.toDays = toDays;
function shouldUpdate(lastUpdate, policy) {
if (policy === 'never') {
return false;
}
if (policy === 'always') {
return true;
}
const now = new Date();
const elapsedTimeInDays = (now.getTime() - lastUpdate.getTime()) / (1000 * 60 * 60 * 24);
const days = toDays(policy);
return elapsedTimeInDays >= days;
}
exports.shouldUpdate = shouldUpdate;
;