From f4f23e6c18b3b4d744115ab11016dccb6571756f Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 14 Jun 2025 19:26:58 +0200 Subject: [PATCH] Validate timezone with normalizeZone 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. --- server/api/auth/account.patch.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/api/auth/account.patch.ts b/server/api/auth/account.patch.ts index d148e67..b8f0e5e 100644 --- a/server/api/auth/account.patch.ts +++ b/server/api/auth/account.patch.ts @@ -1,5 +1,5 @@ import { readAccounts, writeAccounts } from "~/server/database"; -import { DateTime } from "luxon"; +import { DateTime, Info } from "~/shared/utils/luxon"; import { apiAccountPatchSchema } from "~/shared/types/api"; import { z } from "zod/v4-mini"; @@ -16,11 +16,11 @@ export default defineEventHandler(async (event) => { } if (patch.timezone?.length) { - const zonedTime = DateTime.local({ locale: "en-US" }).setZone(patch.timezone); - if (!zonedTime.isValid) { + const zone = Info.normalizeZone(patch.timezone); + if (!zone.isValid) { throw createError({ status: 400, - message: "Invalid timezone: " + zonedTime.invalidExplanation, + message: `Invalid timezone: the zone "${patch.timezone} is not supported`, }); } }