From 38274174a9e8e5754adcb1db21c15d7a3978ff57 Mon Sep 17 00:00:00 2001 From: albertfj114 Date: Fri, 3 Apr 2026 16:15:04 -0400 Subject: [PATCH] feat: add HK parish import parser functions (Tasks 2-6) Implements splitEntries, extractNames, extractFields, normalizeTime, parseScheduleLine, and parseWeekdayLine with 26 passing unit tests. Handles full-width parentheses, language tags, conditional schedule notes, day ranges, and comma-separated day/time lists. Co-Authored-By: Claude Sonnet 4.6 --- scripts/import-hk-parishes.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/import-hk-parishes.ts b/scripts/import-hk-parishes.ts index ba7d712..2520507 100644 --- a/scripts/import-hk-parishes.ts +++ b/scripts/import-hk-parishes.ts @@ -114,7 +114,7 @@ export function extractFields(body: string): { address: string | null; phone: st const normalise = (s: string) => s.replace(/(/g, '(').replace(/)/g, ')').trim(); function extractField(fieldName: string): string | null { - const regex = new RegExp(`\\b${fieldName}\\n([\\s\\S]*?)(?:\\n\\n|\\nFax|\\nEmail|\\nWebsite|\\nChurch|\\nParish|\\nAssistant|\\nDeacon|\\nResident|\\nRector|\\nP\\.C|\\nPastoral|\\nMass Time|$)`, 'i'); + const regex = new RegExp(`\\b${fieldName}\\n([\\s\\S]*?)(?:\\n\\n|\\nFax|\\nEmail|\\nWebsite|\\nChurch|\\nParish|\\nAssistant|\\nDeacon|\\nSister|\\nChairperson|\\nResident|\\nRector|\\nP\\.C|\\nPastoral|\\nMass Time|$)`, 'i'); const m = body.match(regex); if (!m) return null; const value = m[1].replace(/\n/g, ' ').trim(); @@ -142,9 +142,9 @@ export function extractFields(body: string): { address: string | null; phone: st export function normalizeTime(raw: string): string | null { const s = raw.trim().toLowerCase(); if (s.includes('noon')) { + if (s === 'noon') return '12:00'; const m = s.match(/(\d{1,2}):(\d{2})\s*noon/); if (m) return `${String(parseInt(m[1], 10)).padStart(2, '0')}:${m[2]}`; - if (s === '12:00 noon' || s === '12:00noon') return '12:00'; } const m = s.match(/(\d{1,2}):(\d{2})\s*(am|pm|a\.m\.|p\.m\.)/); @@ -239,7 +239,11 @@ function parseDays(prefix: string): number[] { const fromDay = DAY_FULL[rangeMatch[1]] ?? DAY_ABBREV[rangeMatch[1]]; const toDay = DAY_FULL[rangeMatch[2]] ?? DAY_ABBREV[rangeMatch[2]]; if (fromDay !== undefined && toDay !== undefined) { - return Array.from({ length: toDay - fromDay + 1 }, (_, i) => fromDay + i); + const days: number[] = []; + let d = fromDay; + while (d !== toDay) { days.push(d); d = (d + 1) % 7; } + days.push(toDay); + return days; } }