Appwrite datetime attributes return UTC only: where should per-user timezone conversion live in a multi-region app?
0 reputation · 05 Mar 2022, 11:08 UTC
0 reputation · 05 Mar 2022, 11:08 UTC
Appwrite Databases store datetime attributes and system timestamps such as $createdAt and $updatedAt as ISO 8601 strings normalized to UTC. Values written with an offset like 2026-10-14T10:00:00+05:30 come back in UTC, and no per-user or per-document timezone metadata is attached. This means every layer of the stack receives UTC and nothing else.
For an app with users across many regions, the open design question is where conversion belongs. Client-side conversion with the browser's Intl.DateTimeFormat works for display, but Appwrite Functions run server-side with no per-request user locale, so any scheduling or day-boundary logic needs the user's IANA zone passed in explicitly. Storing the zone (e.g. Europe/Berlin) as a profile attribute handles DST correctly, unlike fixed offsets, but adds a lookup step to every server-side operation.
A related pitfall is date-only data: modeling a birthday or due date as a UTC-midnight datetime shifts the calendar day for users behind UTC.
Is storing an IANA zone per user and converting at read time the accepted pattern, or is there a documented Appwrite mechanism I am missing? Should date-only fields be modeled as plain strings instead of datetime attributes? Does this behavior differ between Appwrite Cloud and recent self-hosted versions?
31775 reputation · 05 Mar 2022, 12:09 UTC
Store each user's IANA timezone identifier (e.g., America/New_York) as a string attribute in their profile. Perform conversions to this zone at the point of use: use the browser's native API for UI display and retrieve the stored IANA zone for server-side logic in Appwrite Functions.
$createdAt) as ISO 8601 strings normalized to UTC.Because Appwrite Functions execute in a server-side environment without access to the end-user's local device settings, they lack a request-level locale. Any logic that depends on a user's "today" (such as daily resets or region-specific scheduling) will fail if it relies on the server's system time. By storing the IANA zone in the user profile, you shift the responsibility of timezone context from the infrastructure to the data model, ensuring consistent behavior across different Appwrite Cloud or self-hosted regions.
timezone) to your user profile collection. Populate this during onboarding using Intl.DateTimeFormat().resolvedOptions().timeZone on the client.date-fns-tz to shift the UTC timestamp to the target zone before performing date-boundary calculations.YYYY-MM-DD format. This prevents the "date-shift" bug where a UTC-midnight timestamp is interpreted as the previous calendar day in western timezones.Intl API to format the UTC string returned by Appwrite into the user's current local time for the UI.To verify this setup, create a test document with a UTC timestamp and a user profile set to Asia/Tokyo. Run a function to confirm that the UTC timestamp is correctly shifted to the Tokyo offset, and verify that a YYYY-MM-DD string remains unchanged regardless of the viewing region.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.