Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/lib/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/schema.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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',
Expand Down
Loading