fix: Update timeZoneSchema to handle +00:00 timezone case and maintain IANA compliance (#25776)

* fix: Update timeZoneSchema to handle +00:00 timezone case and maintain IANA compliance

* fix: Use superRefine to properly handle +00:00 timezone and transform to UTC

Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>

* feat: Add logging for non-IANA timezone cases

Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>

* refactor: Simplify timeZoneSchema to use .refine() instead of superRefine

Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>

* chore: Remove warn log for +00:00 timezone to avoid spam

Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>

* chore: Remove logger from timeZone schema

Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Hariom BalharaandDevin AI authored and GitHub committed 2025-12-11 19:46:13 +00:00
1 parent f007fe8407
commit 0ecfd78e47
1 file changed
+15 -3
+15 -3
View File
@@ -3,6 +3,18 @@ import { z } from "zod";
import { isSupportedTimeZone } from "./index";
// Schema for validating IANA timezone strings compatible with Intl.DateTimeFormat
export const timeZoneSchema = z.string().refine((timeZone) => isSupportedTimeZone(timeZone), {
message: "Invalid timezone. Must be a valid IANA timezone string.",
});
// Browserstack and some automations return +00:00 as the timezone which isn't a valid IANA timezone
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions#timezone
export const timeZoneSchema = z
.string()
.refine(
(timeZone) => {
// Allow +00:00 as a special case - it will be transformed to UTC
if (timeZone === "+00:00") {
return true;
}
return isSupportedTimeZone(timeZone);
},
{ message: "Invalid timezone. Must be a valid IANA timezone string." }
)
.transform((timeZone) => (timeZone === "+00:00" ? "UTC" : timeZone));