umami/src/lib/yup.ts

16 lines
359 B
TypeScript
Raw Normal View History

2023-09-25 20:19:56 +00:00
import moment from 'moment';
2023-08-20 05:23:15 +00:00
import * as yup from 'yup';
2023-09-25 20:31:25 +00:00
import { UNIT_TYPES } from './constants';
2023-08-20 05:23:15 +00:00
2023-09-25 20:19:56 +00:00
export const TimezoneTest = yup.string().test(
'timezone',
() => `Invalid timezone`,
2023-09-26 19:30:35 +00:00
value => moment.tz.zone(value) !== null,
2023-09-25 20:31:25 +00:00
);
export const UnitTypeTest = yup.string().test(
'unit',
() => `Invalid unit`,
2023-09-26 19:30:35 +00:00
value => UNIT_TYPES.includes(value),
2023-09-25 20:19:56 +00:00
);