From db4eb125174205259cc0039494a4a5077d32b371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Mu=C3=B1iz?= Date: Tue, 27 Aug 2019 01:22:14 -0700 Subject: [PATCH] Revert formatTime function to previous algorithm --- src/index.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 16ac83b..549bdf8 100644 --- a/src/index.js +++ b/src/index.js @@ -269,6 +269,18 @@ const deleteTZ = (id) => { ) } +const formatTime = (date) => { + const timeformat = localStorage.getItem('timeformat') || '12' + const h = date.getHours() + const m = date.getMinutes() + const hours = timeformat === '12' + ? h === 0 || h === 12 ? '12' : h % 12 + : h + const minutes = m < 10 ? '0' + m : m + + return `${hours}:${minutes}` +} + const refreshDate = async () => { const date = new Date() let status = '' @@ -278,12 +290,7 @@ const refreshDate = async () => { const hour12 = localStorage.getItem('timeformat') && localStorage.getItem('timeformat') !== '12' ? false : '12' const timezones = JSON.parse(localStorage.getItem('timezones')) || [] - $('.time').textContent = date.toLocaleTimeString(navigator.language, { - hour: 'numeric', - minute: 'numeric', - hour12 - }).match(/(\d|\:)*/gi).filter(Boolean)[0] - + $('.time').textContent = formatTime(date) $('.date').textContent = date.toLocaleDateString(navigator.language, { weekday: 'long', month: 'long', day: 'numeric' }) if (showConnection) {