Skip to content

Commit

Permalink
Revert formatTime function to previous algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
krismuniz committed Aug 27, 2019
1 parent 9a1c514 commit db4eb12
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand All @@ -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) {
Expand Down

0 comments on commit db4eb12

Please sign in to comment.