Files
sorsfonalak/services/frontend/src/lib/birth.ts
T
fecoandClaude Opus 5.5 b41dc31f3e
CI / test (push) Successful in 1m49s
CI / build (push) Successful in 5m52s
CI / deploy (push) Skipped
Public birth chart: keep it across pages for the tab, login for the summary
The typed birth data and the calculated chart stay in sessionStorage (no
cookie, gone with the tab), so they are back after visiting another page;
'Adatok törlése' forgets them. User-input storage for the session needs
no consent; the privacy pages say so. Signing up in the same tab fills
the profile with them.

The offer next to the chart now says the short summary needs a login.
Logged-in users get 'Csillagjegyek' in the menu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-21 21:04:26 +00:00

52 lines
1.6 KiB
TypeScript

// Our own date and time fields for birth data (not the browser's date and
// time inputs: those follow the operating system's or the browser's region,
// with US order and AM/PM in Safari).
export 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");
export 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. */
export 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. */
export 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;
}
/** Birth data typed into the public chart page (sessionStorage), offered on the profile after sign-up in the same tab. */
export const BIRTH_DRAFT_KEY = "sf_birth_draft";
export interface BirthDraft {
date: string;
time: string | null;
country: string;
geonames_id: number;
placeName: string;
region: string | null;
}