Skip to content

Commit 26d9289

Browse files
committed
Expose formatTime
1 parent 6d82a92 commit 26d9289

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/format-date-range.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,21 @@ const shortenAmPm = (text: string): string => {
2323

2424
const removeLeadingZero = (text: string): string => text.replace(/^0/, "");
2525

26-
export const createFormatTime =
26+
export const formatTime = (date: Date, locale?: string): string => {
27+
return removeLeadingZero(
28+
shortenAmPm(
29+
date.toLocaleTimeString(locale, {
30+
hour: "2-digit",
31+
minute: "2-digit",
32+
}) || ""
33+
)
34+
);
35+
};
36+
37+
const createFormatTime =
2738
(locale?: string) =>
2839
(date: Date): string =>
29-
removeLeadingZero(
30-
shortenAmPm(
31-
date.toLocaleTimeString(locale, {
32-
hour: "2-digit",
33-
minute: "2-digit",
34-
}) || ""
35-
)
36-
);
40+
formatTime(date, locale);
3741

3842
const getNavigatorLanguage = (): string => {
3943
if (typeof window === "undefined") {

0 commit comments

Comments
 (0)