You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte-kit-vice/src/libs/days/queries.ts

99 lines
2.3 KiB

/**
* Non-mutating queries over date/time values: equality, week math, bounds
* checks, "is weekend", "today", etc. Every function is pure.
*/
import {
CalendarDate,
CalendarDateTime,
Time,
ZonedDateTime
} from './values';
export {
isSameDay,
isSameMonth,
isSameYear,
isEqualDay,
isEqualMonth,
isEqualYear,
isEqualCalendar,
isToday,
isWeekend,
isWeekday,
isBefore,
isAfter,
isBetweenInclusive,
isTimeBefore,
isTimeAfter,
hasTime,
getDayOfWeek,
getHoursInDay,
getDaysInMonth,
getWeeksInMonth,
getMinimumMonthInYear,
getMinimumDayInMonth,
getLastFirstDayOfWeek,
getNextLastDayOfWeek,
startOfMonth,
startOfWeek,
startOfYear,
endOfMonth,
endOfWeek,
endOfYear,
minDate,
maxDate,
areAllDaysBetweenValid,
now,
today,
getLocalTimeZone,
setLocalTimeZone,
resetLocalTimeZone
} from './_vendor/operations/queries';
/** Type guard for `CalendarDate` values. */
export function isCalendarDate(value: unknown): value is CalendarDate {
return value instanceof CalendarDate;
}
/** Type guard for `CalendarDateTime` values. */
export function isCalendarDateTime(value: unknown): value is CalendarDateTime {
return value instanceof CalendarDateTime;
}
/** Type guard for `Time` values. */
export function isTime(value: unknown): value is Time {
return value instanceof Time;
}
/** Type guard for `ZonedDateTime` values. */
export function isDiasZonedDateTime(value: unknown): value is ZonedDateTime {
return value instanceof ZonedDateTime;
}
export { isDiasZonedDateTime as isZonedDateTime };
/**
* Returns the first year of the decade containing `year` (e.g. 2026 →
* 2020, 1999 → 1990). Pure number math, no DateValue allocation.
*
* Used by year-grid range pickers to anchor a 10-year window for
* decade-based pagination.
*/
export function startOfDecadeYear(year: number): number {
return year - (year % 10);
}
/**
* Encodes a `{ year, month }` pair into a strictly-ordered integer key
* (`year * 12 + (month - 1)`) so range comparisons can be done with
* plain `<` / `>` instead of cascading conditionals. Pure math, no
* DateValue allocation.
*
* Used by month-grid range pickers to classify months as start / end /
* in-range across year boundaries.
*/
export function monthOrdinal(year: number, month: number): number {
return year * 12 + (month - 1);
}

Powered by TurnKey Linux.