Rocky_Mountain_Vending/.pnpm-store/v10/files/c2/9b56b931bfdb4e4e0508f8e7f579cf9833a56e96fa3cff887c9d988915e28ecddbd4ce26264dd3522e66f04eee199cfbaf4594f39da2fb3a6f90299a2604d7
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

93 lines
No EOL
3.3 KiB
Text

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addToRange = addToRange;
const DateLib_js_1 = require("../classes/DateLib.js");
/**
* Adds a date to an existing range, considering constraints like minimum and
* maximum range size.
*
* @param date - The date to add to the range.
* @param initialRange - The initial range to which the date will be added.
* @param min - The minimum number of days in the range.
* @param max - The maximum number of days in the range.
* @param required - Whether the range must always include at least one date.
* @param dateLib - The date utility library instance.
* @returns The updated date range, or `undefined` if the range is cleared.
* @group Utilities
*/
function addToRange(date, initialRange, min = 0, max = 0, required = false, dateLib = DateLib_js_1.defaultDateLib) {
const { from, to } = initialRange || {};
const { isSameDay, isAfter, isBefore } = dateLib;
let range;
if (!from && !to) {
// the range is empty, add the date
range = { from: date, to: min > 0 ? undefined : date };
}
else if (from && !to) {
// adding date to an incomplete range
if (isSameDay(from, date)) {
// adding a date equal to the start of the range
if (required) {
range = { from, to: undefined };
}
else {
range = undefined;
}
}
else if (isBefore(date, from)) {
// adding a date before the start of the range
range = { from: date, to: from };
}
else {
// adding a date after the start of the range
range = { from, to: date };
}
}
else if (from && to) {
// adding date to a complete range
if (isSameDay(from, date) && isSameDay(to, date)) {
// adding a date that is equal to both start and end of the range
if (required) {
range = { from, to };
}
else {
range = undefined;
}
}
else if (isSameDay(from, date)) {
// adding a date equal to the the start of the range
range = { from, to: min > 0 ? undefined : date };
}
else if (isSameDay(to, date)) {
// adding a dare equal to the end of the range
range = { from: date, to: min > 0 ? undefined : date };
}
else if (isBefore(date, from)) {
// adding a date before the start of the range
range = { from: date, to: to };
}
else if (isAfter(date, from)) {
// adding a date after the start of the range
range = { from, to: date };
}
else if (isAfter(date, to)) {
// adding a date after the end of the range
range = { from, to: date };
}
else {
throw new Error("Invalid range");
}
}
// check for min / max
if (range?.from && range?.to) {
const diff = dateLib.differenceInCalendarDays(range.to, range.from);
if (max > 0 && diff > max) {
range = { from: date, to: undefined };
}
else if (min > 1 && diff < min) {
range = { from: date, to: undefined };
}
}
return range;
}
//# sourceMappingURL=addToRange.js.map