From de567501a7aef2d4799406b3acc0519bd0932174 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 17 Oct 2019 10:36:46 +0200 Subject: Use so date format for html element id's. --- public/js/app.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index e84c8ce..65bb92f 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -24,17 +24,29 @@ function load_screenings(data_done) { req.send() } +function pad(num) { + return num > 9 ? num.toString() : "0" + num +} + +function time_f(t) { + return pad(t.getHours()) + ":" + pad(t.getMinutes()) +} + function date_f(d) { let opts = { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' } return new Intl.DateTimeFormat('nb-NO', opts).format(d) } +function isodate(d) { + return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate()) +} + window.addEventListener("load", function() { let screenings_by_date = new Map() function _add(screening) { let d = new Date(screening.date || screening.start_time) - let key = date_f(d) + let key = isodate(d) if (!screenings_by_date.has(key)) screenings_by_date.set(key, new Array()) @@ -42,14 +54,6 @@ window.addEventListener("load", function() { s.push(screening) }; - function pad(num) { - return num > 9 ? num.toString() : "0" + num - } - - function time_f(t) { - return pad(t.getHours()) + ":" + pad(t.getMinutes()) - } - function break_text(c, text, x, y, width) { let len = c.measureText(text).width if (len < width) { @@ -173,14 +177,16 @@ window.addEventListener("load", function() { let day = document.createElement('section') let rooms = new Set(s.map( el => el.room.name )) let width = xmargin + 150 * rooms.size + let dateobj = new Date(date) + console.log("dateobj: " + dateobj) - day.id = "program-" + date - day.innerHTML = '

' + date + '

' - + '' + day.id = "program-" + isodate(dateobj) + day.innerHTML = '

' + date_f(dateobj) + '

' + + '' + '' p.appendChild(day) - let canvas = document.getElementById('canvas-' + date) + let canvas = document.getElementById('canvas-' + isodate(dateobj)) let c = canvas.getContext('2d'); c.fillStyle = '#233' c.fillRect(0, 0, width, canvas_height); -- cgit v1.2.3