From c8e1295a4b4175db1f787ef3dc64883eef48a3e6 Mon Sep 17 00:00:00 2001 From: ajnart Date: Wed, 18 May 2022 22:50:53 +0200 Subject: [PATCH] :zap: Improve date module am/pm --- src/components/modules/date/DateModule.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/modules/date/DateModule.tsx b/src/components/modules/date/DateModule.tsx index 7b31f859e..ef7f34216 100644 --- a/src/components/modules/date/DateModule.tsx +++ b/src/components/modules/date/DateModule.tsx @@ -23,7 +23,11 @@ export default function DateComponent(props: any) { const { config } = useConfig(); const hours = date.getHours(); const minutes = date.getMinutes(); - const fullSetting = config.settings[`${DateModule.title}.full`]; + const isFullTime = + config.settings[`${DateModule.title}.full`] === undefined + ? true + : config.settings[`${DateModule.title}.full`]; + const formatString = isFullTime ? 'HH:mm' : 'h:mm a'; // Change date on minute change // Note: Using 10 000ms instead of 1000ms to chill a little :) useEffect(() => { @@ -32,16 +36,9 @@ export default function DateComponent(props: any) { }, 1000 * 60); }, []); - const timeString = `${hours < 10 ? `0${hours}` : hours}:${ - minutes < 10 ? `0${minutes}` : minutes - }`; - const halfTimeString = `${hours < 10 ? `${hours % 12}` : hours % 12}:${ - minutes < 10 ? `0${minutes}` : minutes - } ${hours < 12 ? 'AM' : 'PM'}`; - const finalTimeString = fullSetting ? timeString : halfTimeString; return ( - {finalTimeString} + {dayjs(date).format(formatString)} {dayjs(date).format('dddd, MMMM D')} );