From d6bb9bd15358885de9d09380d5364f801c3be456 Mon Sep 17 00:00:00 2001 From: Bernt Christian Egeland Date: Sat, 18 Feb 2023 16:34:51 +0100 Subject: [PATCH] added use12HourFormat arg to format function --- web/src/utils/dateUtil.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/web/src/utils/dateUtil.ts b/web/src/utils/dateUtil.ts index 39cc993b4..c1ada5f33 100644 --- a/web/src/utils/dateUtil.ts +++ b/web/src/utils/dateUtil.ts @@ -25,7 +25,12 @@ export const getNowYesterdayInLong = (): number => { * @param timezone: string * @returns string - dateTime or 'Invalid time' if unixTimestamp is not provided */ -export const formatUnixTimestampToDateTime = (unixTimestamp: number, locale: string, timezone: string): string => { +export const formatUnixTimestampToDateTime = ( + unixTimestamp: number, + locale: string, + timezone: string, + use12HourFormat: boolean +): string => { if (isNaN(unixTimestamp)) { return 'Invalid time'; } @@ -35,10 +40,11 @@ export const formatUnixTimestampToDateTime = (unixTimestamp: number, locale: str day: '2-digit', month: '2-digit', year: 'numeric', - hour: '2-digit', + hour: use12HourFormat ? 'numeric' : '2-digit', minute: '2-digit', second: '2-digit', timeZone: timezone, + hour12: use12HourFormat !== null ? use12HourFormat : undefined, }); return formatter.format(date); } catch (error) {