1 import type { WeekStartsOn } from '../date-fns-utc/interface';
2 import { browserDateLocale } from '../i18n';
3 import { getIsLocaleAMPM } from '../i18n/dateFnLocale';
4 import type { UserSettings } from '../interfaces';
5 import { SETTINGS_TIME_FORMAT, SETTINGS_WEEK_START } from '../interfaces';
7 export const getDefaultDateFormat = () => {
8 return browserDateLocale.formatLong?.date({ width: 'short' });
11 export const getDefaultTimeFormat = () => {
12 const isAMPM = getIsLocaleAMPM(browserDateLocale);
13 return isAMPM ? SETTINGS_TIME_FORMAT.H12 : SETTINGS_TIME_FORMAT.H24;
16 export const getDefaultWeekStartsOn = (): WeekStartsOn => {
17 const localeWeekStartsOn = browserDateLocale?.options?.weekStartsOn;
18 if (localeWeekStartsOn !== undefined && localeWeekStartsOn >= 0 && localeWeekStartsOn <= 6) {
19 return localeWeekStartsOn;
24 export const getWeekStartsOn = ({ WeekStart }: Pick<UserSettings, 'WeekStart'>): WeekStartsOn => {
25 if (WeekStart === SETTINGS_WEEK_START.LOCALE_DEFAULT) {
26 return getDefaultWeekStartsOn();
28 if (WeekStart >= 1 && WeekStart <= 7) {
29 return (WeekStart % 7) as WeekStartsOn;