Skip to content

Commit c0bd1f2

Browse files
committed
Add formatTime
1 parent ac95a27 commit c0bd1f2

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/locale/formatTime.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { timeFormatter } from 'user-locale';
2+
import { Temporal } from '@js-temporal/polyfill';
3+
import useLocale from './useLocale';
4+
5+
interface TimeFormatterOptions {
6+
precision: 'minute' | 'second';
7+
omitZeroUnits?: boolean;
8+
}
9+
10+
export default function formatTime(time: Temporal.PlainTime | Temporal.PlainDateTime, options: TimeFormatterOptions) {
11+
const [locale] = useLocale();
12+
13+
return timeFormatter(locale.timeFormat, options)(time);
14+
}

0 commit comments

Comments
 (0)