Skip to content

Commit e7d6973

Browse files
committed
feat(date): add formatDate short default options
1 parent f220335 commit e7d6973

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/date.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export function isBetween(date: Date, min: Date, max: Date): boolean {
3131
return min <= date && date <= max;
3232
}
3333

34+
const defaultOptions: Intl.DateTimeFormatOptions = {
35+
dateStyle: 'short',
36+
timeStyle: 'short',
37+
};
38+
3439
export function formatDate(
3540
date: Maybe<string | number | Date>,
3641
params?: {
@@ -45,7 +50,9 @@ export function formatDate(
4550
// Invalid Date
4651
if (Number.isNaN(date.getTime())) return date.toString();
4752

48-
const formatter = new Intl.DateTimeFormat(params?.locales, params?.options);
53+
const { locales, options = defaultOptions } = params ?? {};
54+
55+
const formatter = new Intl.DateTimeFormat(locales, options);
4956

5057
return formatter.format(date);
5158
}

0 commit comments

Comments
 (0)