mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Merge branch 'master' into dev
Some checks failed
Node.js CI / build (postgresql, 18.18, 10) (push) Has been cancelled
Some checks failed
Node.js CI / build (postgresql, 18.18, 10) (push) Has been cancelled
# Conflicts: # .github/workflows/cd.yml # package.json # pnpm-lock.yaml # src/lib/date.ts # src/lib/schema.ts
This commit is contained in:
commit
d23ad5f272
4 changed files with 40 additions and 32 deletions
|
|
@ -103,9 +103,18 @@ export const DATE_FORMATS = {
|
|||
year: 'yyyy',
|
||||
};
|
||||
|
||||
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 {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
import { z } from 'zod';
|
||||
import { isValidTimezone } from '@/lib/date';
|
||||
import { isValidTimezone, normalizeTimezone } from '@/lib/date';
|
||||
import { UNIT_TYPES } from './constants';
|
||||
|
||||
export const timezoneParam = z.string().refine(value => isValidTimezone(value), {
|
||||
message: 'Invalid timezone',
|
||||
});
|
||||
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