mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
feat(vacay): implement Nager.Holidays v4 integration and adapt holiday data structure
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
export interface Holiday {
|
||||
date: string;
|
||||
localName?: string;
|
||||
name?: string;
|
||||
global?: boolean;
|
||||
counties?: string[] | null;
|
||||
}
|
||||
|
||||
interface NagerHolidayV4 {
|
||||
date: string;
|
||||
name: string;
|
||||
nationalHoliday: boolean;
|
||||
subdivisionCodes: string[] | null;
|
||||
}
|
||||
|
||||
/** Adapt Nager.Holidays v4 records to Vacay's long-standing holiday shape. */
|
||||
export function normalizeNagerHolidays(data: unknown): Holiday[] | undefined {
|
||||
if (!Array.isArray(data)) return undefined;
|
||||
const holidays: Holiday[] = [];
|
||||
for (const row of data) {
|
||||
if (
|
||||
!row ||
|
||||
typeof row !== 'object' ||
|
||||
typeof row.date !== 'string' ||
|
||||
typeof row.name !== 'string' ||
|
||||
typeof row.nationalHoliday !== 'boolean' ||
|
||||
(row.subdivisionCodes !== null &&
|
||||
(!Array.isArray(row.subdivisionCodes) ||
|
||||
row.subdivisionCodes.some((code: unknown) => typeof code !== 'string')))
|
||||
)
|
||||
return undefined;
|
||||
const holiday = row as NagerHolidayV4;
|
||||
holidays.push({
|
||||
date: holiday.date,
|
||||
name: holiday.name,
|
||||
localName: holiday.name,
|
||||
global: holiday.nationalHoliday,
|
||||
counties: holiday.subdivisionCodes,
|
||||
});
|
||||
}
|
||||
return holidays;
|
||||
}
|
||||
@@ -28,10 +28,12 @@ import { VacayUserSettings as VacayUserSettingsEntity } from '../../db/entities/
|
||||
import type { VacayUserSettingsRepository } from '../../db/repositories/VacayUserSettings.repository';
|
||||
import { SchoolHolidayRegions } from '../../db/entities/SchoolHolidayRegions.entity';
|
||||
import type { SchoolHolidayRegionsRepository } from '../../db/repositories/SchoolHolidayRegions.repository';
|
||||
import { normalizeNagerHolidays, type Holiday } from './vacay.holidays';
|
||||
import {
|
||||
daysAlwaysInMonth, isBlockedWeekend, normalizeFraction, normalizeKind, normalizeYearType, pad2, parseAsUtcMillis,
|
||||
shiftIsoDate, windowEndYear, CACHE_TTL, COLORS, COUNTRY_RE, FETCH_TIMEOUT_MS, MAX_HOLIDAY_BYTES, YEAR_RE,
|
||||
} from './vacay.helpers';
|
||||
export type { Holiday } from './vacay.holidays';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Types
|
||||
@@ -72,45 +74,6 @@ export interface VacayPlanMember {
|
||||
created_at?: string;
|
||||
}
|
||||
|
||||
export interface Holiday {
|
||||
date: string;
|
||||
localName?: string;
|
||||
name?: string;
|
||||
global?: boolean;
|
||||
counties?: string[] | null;
|
||||
}
|
||||
|
||||
interface NagerHolidayV4 {
|
||||
date: string;
|
||||
name: string;
|
||||
nationalHoliday: boolean;
|
||||
subdivisionCodes: string[] | null;
|
||||
}
|
||||
|
||||
/** Adapt Nager.Holidays v4 records to Vacay's long-standing holiday shape. */
|
||||
function normalizeNagerHolidays(data: unknown): Holiday[] | undefined {
|
||||
if (!Array.isArray(data)) return undefined;
|
||||
const holidays: Holiday[] = [];
|
||||
for (const row of data) {
|
||||
if (
|
||||
!row || typeof row !== 'object' ||
|
||||
typeof row.date !== 'string' || typeof row.name !== 'string' ||
|
||||
typeof row.nationalHoliday !== 'boolean' ||
|
||||
(row.subdivisionCodes !== null &&
|
||||
(!Array.isArray(row.subdivisionCodes) || row.subdivisionCodes.some((code: unknown) => typeof code !== 'string')))
|
||||
) return undefined;
|
||||
const holiday = row as NagerHolidayV4;
|
||||
holidays.push({
|
||||
date: holiday.date,
|
||||
name: holiday.name,
|
||||
localName: holiday.name,
|
||||
global: holiday.nationalHoliday,
|
||||
counties: holiday.subdivisionCodes,
|
||||
});
|
||||
}
|
||||
return holidays;
|
||||
}
|
||||
|
||||
export interface SchoolHoliday {
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
|
||||
Reference in New Issue
Block a user