mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
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
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:
commit
eca6b069f6
2 changed files with 13 additions and 4 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue