Booking flow: required terms and privacy checkbox with i18n
Also includes admin, dashboard, and API updates; PWA icon assets; and assorted layout and utility changes on dev.
This commit is contained in:
@@ -41,6 +41,49 @@ export function toDbDate(date: Date | string): string | Date {
|
||||
return getDbType() === 'postgres' ? d : d.toISOString();
|
||||
}
|
||||
|
||||
const NAIVE_DATETIME_RE = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?$/;
|
||||
|
||||
/**
|
||||
* Parse a datetime string that represents wall-clock time in a given timezone
|
||||
* and return the corresponding UTC Date.
|
||||
*
|
||||
* Naive strings (no "Z" or offset) are interpreted as wall-clock time in
|
||||
* `timezone`. Strings that already carry a timezone indicator are parsed
|
||||
* directly so existing UTC ISO values still work.
|
||||
*/
|
||||
export function parseEventDatetime(
|
||||
datetime: string,
|
||||
timezone: string = 'America/Asuncion',
|
||||
): Date {
|
||||
if (!NAIVE_DATETIME_RE.test(datetime)) {
|
||||
return new Date(datetime);
|
||||
}
|
||||
|
||||
// Treat the digits as UTC so we have a stable reference instant.
|
||||
const fakeUTC = new Date(datetime + 'Z');
|
||||
|
||||
// Ask Intl what that UTC instant looks like in both UTC and the target tz.
|
||||
const utcStr = fakeUTC.toLocaleString('en-US', { timeZone: 'UTC' });
|
||||
const tzStr = fakeUTC.toLocaleString('en-US', { timeZone: timezone });
|
||||
|
||||
// The gap between the two tells us the tz offset at this point in time.
|
||||
const offsetMs = new Date(utcStr).getTime() - new Date(tzStr).getTime();
|
||||
|
||||
return new Date(fakeUTC.getTime() + offsetMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a datetime string to the appropriate DB format, interpreting naive
|
||||
* strings as wall-clock time in `timezone` (defaults to America/Asuncion).
|
||||
*/
|
||||
export function toDbDateTz(
|
||||
datetime: string,
|
||||
timezone: string = 'America/Asuncion',
|
||||
): string | Date {
|
||||
const d = parseEventDatetime(datetime, timezone);
|
||||
return getDbType() === 'postgres' ? d : d.toISOString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a boolean value to the appropriate format for the database type.
|
||||
* - SQLite: returns boolean (true/false) for mode: 'boolean'
|
||||
|
||||
Reference in New Issue
Block a user