Rocky_Mountain_Vending/.pnpm-store/v10/files/88/70b79d023ee2815a54d3056b7c164dac2c5658ec0ad9ec59edd7fee986a76d8b638b2388364b00f9159edba2d00bfb398e230a6ebdf0dc2d2f84f6681de279
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

78 lines
2.4 KiB
Text

import { type DateLib, defaultDateLib } from "../classes/DateLib.js";
import type { Matcher } from "../types/index.js";
import { rangeIncludesDate } from "./rangeIncludesDate.js";
import {
isDateAfterType,
isDateBeforeType,
isDateInterval,
isDateRange,
isDatesArray,
isDayOfWeekType
} from "./typeguards.js";
/**
* Checks if a given date matches at least one of the specified {@link Matcher}.
*
* @param date - The date to check.
* @param matchers - The matchers to check against.
* @param dateLib - The date utility library instance.
* @returns `true` if the date matches any of the matchers, otherwise `false`.
* @group Utilities
*/
export function dateMatchModifiers(
date: Date,
matchers: Matcher | Matcher[],
dateLib: DateLib = defaultDateLib
): boolean {
const matchersArr = !Array.isArray(matchers) ? [matchers] : matchers;
const { isSameDay, differenceInCalendarDays, isAfter } = dateLib;
return matchersArr.some((matcher: Matcher) => {
if (typeof matcher === "boolean") {
return matcher;
}
if (dateLib.isDate(matcher)) {
return isSameDay(date, matcher);
}
if (isDatesArray(matcher, dateLib)) {
return matcher.includes(date);
}
if (isDateRange(matcher)) {
return rangeIncludesDate(matcher, date, false, dateLib);
}
if (isDayOfWeekType(matcher)) {
if (!Array.isArray(matcher.dayOfWeek)) {
return matcher.dayOfWeek === date.getDay();
}
return matcher.dayOfWeek.includes(date.getDay());
}
if (isDateInterval(matcher)) {
const diffBefore = differenceInCalendarDays(matcher.before, date);
const diffAfter = differenceInCalendarDays(matcher.after, date);
const isDayBefore = diffBefore > 0;
const isDayAfter = diffAfter < 0;
const isClosedInterval = isAfter(matcher.before, matcher.after);
if (isClosedInterval) {
return isDayAfter && isDayBefore;
} else {
return isDayBefore || isDayAfter;
}
}
if (isDateAfterType(matcher)) {
return differenceInCalendarDays(date, matcher.after) > 0;
}
if (isDateBeforeType(matcher)) {
return differenceInCalendarDays(matcher.before, date) > 0;
}
if (typeof matcher === "function") {
return matcher(date);
}
return false;
});
}
/**
* @private
* @deprecated Use {@link dateMatchModifiers} instead.
*/
export const isMatch = dateMatchModifiers;