diff options
-rw-r--r-- | public/js/app.js | 32 |
1 files 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 = '<h2>' + date + '</h2>' - + '<canvas id="canvas-' + date + '" height="' + canvas_height + '" width="' + width + '">' + day.id = "program-" + isodate(dateobj) + day.innerHTML = '<h2>' + date_f(dateobj) + '</h2>' + + '<canvas id="canvas-' + isodate(dateobj) + '" height="' + canvas_height + '" width="' + width + '">' + '</canvas>' 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); |