feat: support pickup booking date ranges
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user