mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
fix(profile): report the time zone the server uses on /api/user/profile
`/api/auth/me` has reported the resolved zone, the stored one or the instance default when the stored value is unusable, while `/api/user/profile` returned the raw column. A client reading the profile could cut days differently from the server, and sending the value back in a PATCH was refused. Both reads, and the profile PATCH answer, now go through one `resolveStoredTimezone`. The field stays a string and always holds a valid IANA name. The web account editor already reads the resolved zone from `/api/auth/me` and saves through the validating timezone route, so it shows the zone in use and can only write a valid one.
This commit is contained in:
1 parent
0cc73d3c88
commit
be112df972
6 files changed
+124
-11
No files matched your search
@@ -498,7 +498,11 @@ const profileResponse = z
|
||||
gender: z.enum(["MALE", "FEMALE", "OTHER"]).nullable(),
|
||||
heightCm: z.number().nullable(),
|
||||
locale: z.string().nullable(),
|
||||
timezone: z.string(),
|
||||
timezone: z
|
||||
.string()
|
||||
.describe(
|
||||
"The IANA zone the server cuts this account's days in, the same value `/api/auth/me` reports: the stored zone, or the instance default when the stored value is not a usable IANA name (since v1.39.1; before, the raw stored value). Always a valid IANA name, so sending it back in a PATCH is accepted.",
|
||||
),
|
||||
timeFormat: z
|
||||
.enum(["AUTO", "H12", "H24"])
|
||||
.describe(
|
||||
@@ -542,7 +546,11 @@ const profileUpdateResponse = z
|
||||
gender: z.enum(["MALE", "FEMALE", "OTHER"]).nullable(),
|
||||
heightCm: z.number().nullable(),
|
||||
locale: z.string().nullable(),
|
||||
timezone: z.string(),
|
||||
timezone: z
|
||||
.string()
|
||||
.describe(
|
||||
"The IANA zone the server cuts this account's days in, the same value `/api/auth/me` reports: the stored zone, or the instance default when the stored value is not a usable IANA name (since v1.39.1; before, the raw stored value). Always a valid IANA name, so sending it back in a PATCH is accepted.",
|
||||
),
|
||||
timeFormat: z
|
||||
.enum(["AUTO", "H12", "H24"])
|
||||
.describe(
|
||||
|
||||
@@ -144,6 +144,21 @@ export async function resolveServerDefaultTimezone(): Promise<string> {
|
||||
return tz;
|
||||
}
|
||||
|
||||
/**
|
||||
* The zone the server actually uses for a stored `User.timezone` value: the
|
||||
* value itself when it is a usable IANA name, the instance default otherwise.
|
||||
*
|
||||
* Every response that reports an account's zone goes through this, so a
|
||||
* client never buckets days by a value the server itself has set aside.
|
||||
*/
|
||||
export async function resolveStoredTimezone(
|
||||
stored: string | null | undefined,
|
||||
): Promise<string> {
|
||||
return stored && isValidTimezone(stored)
|
||||
? stored
|
||||
: resolveServerDefaultTimezone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the per-user display timezone. Reads `User.timezone`. Falls
|
||||
* back to the server default and then to "Europe/Berlin". Cached for
|
||||
|
||||
Reference in new issue
Block a user