From b11ad29876a7c60e3e3e36b4791f010985f38fa4 Mon Sep 17 00:00:00 2001 From: Humberto Alfonso Díaz Date: Thu, 7 Nov 2019 18:38:21 +0100 Subject: FUNCT Add support to dinamically update header time --- src/js/time.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/js/time.js (limited to 'src/js/time.js') diff --git a/src/js/time.js b/src/js/time.js new file mode 100644 index 0000000..55165c7 --- /dev/null +++ b/src/js/time.js @@ -0,0 +1,33 @@ +import Mustache from 'mustache'; + +var template; + +var days = ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY']; + +function formatAMPM(date) { + var hours = date.getHours(); + var minutes = date.getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; + minutes = minutes < 10 ? '0'+minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; + } + +function initInterval() { + setInterval(function() { + var date = new Date(); + document.getElementById('timeContainer').innerHTML = Mustache.render(template, { + day: days[date.getDay()], + hour: formatAMPM(date) + }); + }, 1000); +} + +export function init() { + template = document.getElementById('time-template').innerHTML; + Mustache.parse(template); + + initInterval(); +} \ No newline at end of file -- cgit 1.2.3-korg