diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2019-10-17 10:36:46 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2019-10-17 10:36:46 +0200 |
commit | de567501a7aef2d4799406b3acc0519bd0932174 (patch) | |
tree | fcd43e40da0393794fc269765f776866f98f1c7d | |
parent | 81ada79bad3ef33e3c8cb1709d09a6087f15aa07 (diff) | |
download | ramaskrik-social-de567501a7aef2d4799406b3acc0519bd0932174.tar.gz ramaskrik-social-de567501a7aef2d4799406b3acc0519bd0932174.tar.bz2 ramaskrik-social-de567501a7aef2d4799406b3acc0519bd0932174.zip |
Use so date format for html element id's.ramaskrik-2019
-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); |