feat: support pickup booking date ranges

This commit is contained in:
root
2025-11-09 19:11:26 +01:00
parent 1a7aa0e1b3
commit 3f8f1f24eb
4 changed files with 186 additions and 19 deletions

View File

@@ -78,17 +78,41 @@ async function ensureSession(session) {
}
}
function matchesDesiredDate(pickupDate, desiredDate) {
if (!desiredDate) {
function toDateValue(input) {
if (!input) {
return null;
}
const date = input instanceof Date ? new Date(input.getTime()) : new Date(input);
if (Number.isNaN(date.getTime())) {
return null;
}
return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
}
function matchesDesiredDate(pickupDate, desiredDate, desiredDateRange) {
const pickupValue = toDateValue(pickupDate);
if (pickupValue === null) {
return false;
}
const hasRange = Boolean(desiredDateRange && (desiredDateRange.start || desiredDateRange.end));
if (hasRange) {
const startValue = toDateValue(desiredDateRange.start);
const endValue = toDateValue(desiredDateRange.end);
if (startValue !== null && pickupValue < startValue) {
return false;
}
if (endValue !== null && pickupValue > endValue) {
return false;
}
return true;
}
const desired = new Date(desiredDate);
return (
pickupDate.getFullYear() === desired.getFullYear() &&
pickupDate.getMonth() === desired.getMonth() &&
pickupDate.getDate() === desired.getDate()
);
const desiredValue = toDateValue(desiredDate);
if (desiredValue === null) {
return true;
}
return pickupValue === desiredValue;
}
function matchesDesiredWeekday(pickupDate, desiredWeekday) {
@@ -158,7 +182,7 @@ async function checkEntry(sessionId, entry, settings) {
pickups.forEach((pickup) => {
const pickupDate = new Date(pickup.date);
if (!matchesDesiredDate(pickupDate, entry.desiredDate)) {
if (!matchesDesiredDate(pickupDate, entry.desiredDate, entry.desiredDateRange)) {
return;
}
if (!matchesDesiredWeekday(pickupDate, desiredWeekday)) {