diff --git a/src/utils/datetime.ts b/src/utils/datetime.ts index b2a4a434..de14c2e1 100644 --- a/src/utils/datetime.ts +++ b/src/utils/datetime.ts @@ -15,6 +15,9 @@ export function dateFormatJS(opts: { dayStyle?: 'numeric' | '2-digit'; monthStyle?: 'numeric' | '2-digit' | 'long' | 'short'; timeStyle?: 'full' | 'long' | 'medium' | 'short'; + noDay?: boolean; + noMonth?: boolean; + noYear?: boolean; }) { const dt = opts.date ? new Date(opts.date) : new Date(); @@ -25,10 +28,10 @@ export function dateFormatJS(opts: { } let formatted = new Intl.DateTimeFormat(opts.locale, { - day: opts.dayStyle || 'numeric', - month: opts.monthStyle || 'short', + day: opts.noDay ? undefined : opts.dayStyle || 'numeric', + month: opts.noMonth ? undefined : opts.monthStyle || 'short', timeStyle: opts.timeStyle, - year: 'numeric', + year: opts.noYear ? undefined : 'numeric', }).format(dt); switch (opts.locale) { @@ -42,9 +45,8 @@ export function dateFormatJS(opts: { } /** - * @deprecated Please use dateFormatJS. + * @deprecated use dateFormatJS instead. */ - export function dateFormat( date?: string | Date | null, fullmonth = false, diff --git a/src/utils/ui.ts b/src/utils/ui.ts index e9b1947f..29f2ca9b 100644 --- a/src/utils/ui.ts +++ b/src/utils/ui.ts @@ -25,17 +25,17 @@ export function initTheme(): Theme { * **Warning:** Must be called after initialize vue and quasar. */ export function setTheme(theme: Theme): Theme { - localStorage.setItem('currentTheme', theme); - - if (theme !== Theme.Auto) { - Dark.set(theme === Theme.Dark); + switch (theme) { + case Theme.Light: + case Theme.Dark: + localStorage.setItem('currentTheme', theme); + Dark.set(theme !== Theme.Dark); + return theme; + default: + localStorage.setItem('currentTheme', Theme.Auto); + Dark.set(window.matchMedia('(prefers-color-scheme: dark)').matches); + return Theme.Auto; } - - if (theme === Theme.Auto) { - Dark.set(window.matchMedia('(prefers-color-scheme: dark)').matches); - } - - return theme; } export enum Lang { @@ -49,16 +49,15 @@ export enum Lang { * **Warning:** Must be used after initialize vue and vue-i18n */ export function initLang(): Lang { - const { locale } = i18n.global; const current = localStorage.getItem('currentLanguage') as Lang | null; - if (current !== Lang.English && current !== Lang.Thai) { - return setLang(Lang.Thai); + switch (current) { + case Lang.English: + case Lang.Thai: + return setLang(current); + default: + return setLang(Lang.Thai); } - - if (!current) return setLang(locale.value as Lang); - - return setLang(current); } /**