From d63cdf737a64e056a7a5e3d71ed72b8de5f51ac8 Mon Sep 17 00:00:00 2001 From: feco Date: Fri, 20 Nov 2026 21:34:49 +0000 Subject: [PATCH] Birth date and time: our own Hungarian fields The browser's date and time inputs follow the operating system's or the browser's region, not the page: Safari wanted US order and AM/PM (and did not take minutes without it), Chrome showed its own language. Now the year, a month list with Hungarian names and a day list, and hour and minute fields (24-hour, the cursor moves on after the hour), the same in every browser. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL --- services/frontend/src/app/globals.css | 10 + .../frontend/src/app/profil/BirthForm.tsx | 177 +++++++++++++++--- 2 files changed, 156 insertions(+), 31 deletions(-) diff --git a/services/frontend/src/app/globals.css b/services/frontend/src/app/globals.css index 39f83f8..966cb57 100644 --- a/services/frontend/src/app/globals.css +++ b/services/frontend/src/app/globals.css @@ -1104,3 +1104,13 @@ span.tarot-fan-card { cursor: default; } @media (prefers-reduced-motion: reduce) { .tarot-flip-inner, .tarot-fan-card, .tarot-demo-text { transition: none; animation: none; } } + +/* Birth date and time: our own Hungarian fields (not the browser's date and time inputs) */ +.birth-fields { border: 0; margin: 0; padding: 0; min-width: 0; } +.birth-fields legend { padding: 0; margin-bottom: 8px; } +.birth-row { display: flex; align-items: center; gap: 8px; } +.birth-year { width: 5.5em; flex: none; } +.birth-month { flex: 1 1 auto; min-width: 0; } +.birth-day { width: 5.2em; flex: none; } +.birth-time { width: 4.4em; flex: none; text-align: center; } +.birth-colon { color: var(--muted); font-weight: 600; } diff --git a/services/frontend/src/app/profil/BirthForm.tsx b/services/frontend/src/app/profil/BirthForm.tsx index 0e156b4..775e668 100644 --- a/services/frontend/src/app/profil/BirthForm.tsx +++ b/services/frontend/src/app/profil/BirthForm.tsx @@ -16,6 +16,41 @@ const ERRORS: Record = { invalid_date: "Érvénytelen dátum.", }; +const MONTHS = [ + "január", + "február", + "március", + "április", + "május", + "június", + "július", + "augusztus", + "szeptember", + "október", + "november", + "december", +]; + +const pad = (n: number) => String(n).padStart(2, "0"); +const daysIn = (year: number, month: number) => new Date(Date.UTC(year || 2000, month, 0)).getUTCDate(); + +/** "YYYY-MM-DD" from the three fields, or null while it is not a real date. */ +function composeDate(year: string, month: string, day: string): string | null { + const y = Number(year); + const m = Number(month); + const d = Number(day); + if (!/^\d{4}$/.test(year) || y < 1000 || !m || !d || d > daysIn(y, m)) return null; + return `${year}-${pad(m)}-${pad(d)}`; +} + +/** "HH:MM" from the two fields, or null while it is not a real time. */ +function composeTime(hour: string, minute: string): string | null { + if (!/^\d{1,2}$/.test(hour) || !/^\d{1,2}$/.test(minute)) return null; + const h = Number(hour); + const m = Number(minute); + return h <= 23 && m <= 59 ? `${pad(h)}:${pad(m)}` : null; +} + /** Someone else's chart: added with a name, or (with `chartId`) corrected. */ export type PersonTarget = { chartId?: string; name?: string }; @@ -32,8 +67,16 @@ export function BirthForm({ onSaved: (chartId: string) => void; }) { const [name, setName] = useState(person?.name ?? ""); - const [date, setDate] = useState(initial?.date ?? ""); - const [time, setTime] = useState(initial?.time?.slice(0, 5) ?? ""); + // Our own fields, not the browser's date and time inputs: those follow the + // operating system's or the browser's region (US order, AM/PM in Safari). + const [year, setYear] = useState(initial?.date?.slice(0, 4) ?? ""); + const [month, setMonth] = useState(initial?.date ? String(Number(initial.date.slice(5, 7))) : ""); + const [day, setDay] = useState(initial?.date ? String(Number(initial.date.slice(8, 10))) : ""); + const [hour, setHour] = useState(initial?.time?.slice(0, 2) ?? ""); + const [minute, setMinute] = useState(initial?.time?.slice(3, 5) ?? ""); + const minuteRef = useRef(null); + const date = composeDate(year, month, day) ?? ""; + const time = composeTime(hour, minute) ?? ""; const [timeUnknown, setTimeUnknown] = useState(initial ? !initial.time : false); const [country, setCountry] = useState(initial?.country ?? "HU"); const [place, setPlace] = useState( @@ -57,8 +100,11 @@ export function BirthForm({ e.preventDefault(); setError(null); if (person && !name.trim()) return setError("Add meg a nevét."); - if (!date) return setError("Add meg a születési dátumot."); - if (!timeUnknown && !time) return setError("Add meg a születési időt, vagy jelöld, hogy nem tudod."); + if (!year && !month && !day) return setError("Add meg a születési dátumot."); + if (!date) return setError("Ellenőrizd a dátumot: az év négy számjegy, és a nap legyen az adott hónapban."); + if (date > today) return setError("A születési dátum nem lehet a jövőben."); + if (!timeUnknown && !hour && !minute) return setError("Add meg a születési időt, vagy jelöld, hogy nem tudod."); + if (!timeUnknown && !time) return setError("Ellenőrizd az időt: óra 0–23, perc 0–59."); if (!place) return setError("Válaszd ki a születési helyet a listából."); setBusy(true); try { @@ -120,37 +166,106 @@ export function BirthForm({ )}
-
- - setDate(e.target.value)} - required - /> -
-
- - { - setTime(e.target.value); - setAmbiguous(false); - }} - /> +
+ Születési dátum +
+ + setYear(e.target.value.replace(/\D/g, ""))} + /> + + + + +
+
+
+ Születési idő (helyi idő) +
+ + { + const v = e.target.value.replace(/\D/g, ""); + setHour(v); + setAmbiguous(false); + // Two digits (or one that cannot start a valid hour): on to the minutes. + if (v.length === 2 || (v.length === 1 && Number(v) > 2)) minuteRef.current?.focus(); + }} + /> + + + { + setMinute(e.target.value.replace(/\D/g, "")); + setAmbiguous(false); + }} + /> +
-
+