refactor: use switch case instead
This commit is contained in:
parent
d8844e7599
commit
5e524ec91d
2 changed files with 23 additions and 22 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue