Merge pull request #3633 from mcnaveen/fix/asia-kolkata-tz
Some checks failed
Create docker images / Build, push, and deploy (push) Has been cancelled
Create docker images / Build, push, and deploy-1 (push) Has been cancelled
Node.js CI / build (mysql, 18.18, 10) (push) Has been cancelled
Node.js CI / build (postgresql, 18.18, 10) (push) Has been cancelled

feat (timezone): normalization function for handling legacy timezone identifiers
This commit is contained in:
Mike Cao 2025-09-24 12:55:20 -07:00 committed by GitHub
commit eca6b069f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View file

@ -104,9 +104,18 @@ const DATE_FUNCTIONS = {
},
};
const TIMEZONE_MAPPINGS: Record<string, string> = {
'Asia/Calcutta': 'Asia/Kolkata',
};
export function normalizeTimezone(timezone: string): string {
return TIMEZONE_MAPPINGS[timezone] || timezone;
}
export function isValidTimezone(timezone: string) {
try {
Intl.DateTimeFormat(undefined, { timeZone: timezone });
const normalizedTimezone = normalizeTimezone(timezone);
Intl.DateTimeFormat(undefined, { timeZone: normalizedTimezone });
return true;
} catch (error) {
return false;

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { isValidTimezone } from '@/lib/date';
import { isValidTimezone, normalizeTimezone } from '@/lib/date';
import { UNIT_TYPES } from './constants';
export const filterParams = {
@ -28,9 +28,9 @@ export const pagingParams = {
search: z.string().optional(),
};
export const timezoneParam = z.string().refine(value => isValidTimezone(value), {
export const timezoneParam = z.string().refine((value: string) => isValidTimezone(value), {
message: 'Invalid timezone',
});
}).transform((value: string) => normalizeTimezone(value));
export const unitParam = z.string().refine(value => UNIT_TYPES.includes(value), {
message: 'Invalid unit',