From b097a8fc370215a0940c249fa74fd01a21871e81 Mon Sep 17 00:00:00 2001 From: Adorian Doran Date: Tue, 10 Dec 2024 17:13:46 +0200 Subject: [PATCH] client: create a date formatter utility --- src/public/app/utils/formatters.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/public/app/utils/formatters.js diff --git a/src/public/app/utils/formatters.js b/src/public/app/utils/formatters.js new file mode 100644 index 000000000..f59e3144f --- /dev/null +++ b/src/public/app/utils/formatters.js @@ -0,0 +1,14 @@ +/** + * Formats the given date to a string based on the current locale. + * @param {Date | number} date + * @param {"full" | "long" | "medium" | "short" | undefined} dateStyle + * @param {"full" | "long" | "medium" | "short" | undefined} tiemStyle + */ +export function formatDate(date, dateStyle = "medium", tiemStyle = "medium") { + const formatter = new Intl.DateTimeFormat(navigator.language, { + dateStyle: "medium", + timeStyle: "medium" + }); + + return formatter.format(date); +} \ No newline at end of file