Validate timezone with normalizeZone
All checks were successful
/ build (push) Successful in 1m29s
/ deploy (push) Successful in 16s

Instead of constructing a new DateTime object and seeing if it
succeeded, validate the client's timezone selection using the
Info.normalizeZone utility function.  This prevents throwing an
unexpected error creating the DateTime object after the change
in e100555 to throw on invalid dates.
This commit is contained in:
Hornwitser 2025-06-14 19:26:58 +02:00
parent bb450fd583
commit f4f23e6c18

View file

@ -1,5 +1,5 @@
import { readAccounts, writeAccounts } from "~/server/database"; import { readAccounts, writeAccounts } from "~/server/database";
import { DateTime } from "luxon"; import { DateTime, Info } from "~/shared/utils/luxon";
import { apiAccountPatchSchema } from "~/shared/types/api"; import { apiAccountPatchSchema } from "~/shared/types/api";
import { z } from "zod/v4-mini"; import { z } from "zod/v4-mini";
@ -16,11 +16,11 @@ export default defineEventHandler(async (event) => {
} }
if (patch.timezone?.length) { if (patch.timezone?.length) {
const zonedTime = DateTime.local({ locale: "en-US" }).setZone(patch.timezone); const zone = Info.normalizeZone(patch.timezone);
if (!zonedTime.isValid) { if (!zone.isValid) {
throw createError({ throw createError({
status: 400, status: 400,
message: "Invalid timezone: " + zonedTime.invalidExplanation, message: `Invalid timezone: the zone "${patch.timezone} is not supported`,
}); });
} }
} }