From f9814bd935f6ddb2454181bbf24ec75a487228ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 17 Aug 2020 15:52:33 +0200 Subject: Fix date output on long events. --- module/html/vcomponent.scm | 32 +++++++++++++++++++------------- module/vcomponent/datetime/output.scm | 11 +++++------ static/script.js | 18 +++++++++--------- static/style.scss | 2 +- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/module/html/vcomponent.scm b/module/html/vcomponent.scm index 9efaf77d..b4538fbd 100644 --- a/module/html/vcomponent.scm +++ b/module/html/vcomponent.scm @@ -65,18 +65,22 @@ `(span (@ (class "summary")) ,(prop ev 'SUMMARY)))) (div ,(call-with-values (lambda () (fmt-time-span ev)) - (case-lambda [(start) `(div (span (@ (class "dtstart") - (data-fmt "%L%H:%M")) - ,start))] - [(start end) `(div (span (@ (class "dtstart") - ;; TODO same format string - ;; as fmt-time-span used - (data-fmt "%L%H:%M")) - ,start) - " — " - (span (@ (class "dtend") - (data-fmt "%L%H:%M")) - ,end))])) + (case-lambda [(start) + `(div (span (@ (class "dtstart") + (data-fmt ,(string-append "~L" start))) + ,(datetime->string + (as-datetime (prop ev 'DTSTART)) + start)))] + [(start end) + `(div (span (@ (class "dtstart") + (data-fmt ,(string-append "~L" start))) + ,(datetime->string (as-datetime (prop ev 'DTSTART)) + start)) + " — " + (span (@ (class "dtend") + (data-fmt ,(string-append "~L" end))) + ,(datetime->string (as-datetime (prop ev 'DTEND)) + end)))])) ,(when (and=> (prop ev 'LOCATION) (negate string-null?)) `(div (b "Plats: ") (div (@ (class "location")) @@ -198,7 +202,9 @@ ,(tabset `(("📅" title: "Översikt" - ,(fmt-single-event ev)) + ,(begin(format (current-error-port) + "start=~a end=~a~%" (prop ev 'DTSTART) + (prop ev 'DTEND)) (fmt-single-event ev))) ("⤓" title: "Nedladdning" (div (@ (class "eventtext") (style "font-family:sans")) (h2 "Ladda ner") diff --git a/module/vcomponent/datetime/output.scm b/module/vcomponent/datetime/output.scm index 48c89783..c76f010f 100644 --- a/module/vcomponent/datetime/output.scm +++ b/module/vcomponent/datetime/output.scm @@ -54,9 +54,9 @@ (cond [(prop ev 'DTEND) => (lambda (e) (if (date= e (date+ s (date day: 1))) - (date->string s) ; start = end, only return one value - (values (date->string s) - (date->string e))))] + "~Y-~m-~d" ; start = end, only return one value + (values "~Y-~m-~d" + "~Y-~m-~d")))] ;; no end value, just return start [else (date->string s)]))] [else ; guaranteed datetime @@ -65,6 +65,5 @@ (if e (let ((fmt-str (if (date= (get-date s) (get-date e)) "~H:~M" "~Y-~m-~d ~H:~M"))) - (values (datetime->string s fmt-str) - (datetime->string e fmt-str))) - (datetime->string s "~Y-~m-~d ~H:~M")))])) + (values fmt-str fmt-str)) + "~Y-~m-~d ~H:~M"))])) diff --git a/static/script.js b/static/script.js index 0d1ed7e2..acbe7ca8 100644 --- a/static/script.js +++ b/static/script.js @@ -342,7 +342,7 @@ function update_current_time_bar () { if (! (start_time <= now.getTime() && now.getTime() < end_time)) return; - var event_area = document.getElementById(now.format("%Y-%m-%d")) + var event_area = document.getElementById(now.format("~Y-~m-~d")) if (event_area) { if (bar_object) { @@ -364,13 +364,13 @@ function update_current_time_bar () { current_cell.style.border = ""; } current_cell = document.querySelector( - ".small-calendar time[datetime='" + now.format("%Y-%m-%d") + "']"); + ".small-calendar time[datetime='" + now.format("~Y-~m-~d") + "']"); current_cell.style.border = "1px solid black"; /* Update [today] button */ document.getElementById("today-button").href - = (new Date).format("%Y-%m-%d") + ".html"; + = (new Date).format("~Y-~m-~d") + ".html"; } function setVar(str, val) { @@ -458,7 +458,7 @@ function place_in_edit_mode (event) { }); let slot = event.properties["_slot_" + fieldname] let idx = slot.findIndex(e => e[0] === field); - slot.splice(idx, 1, [input, (s, v) => s.value = v.format("%H:%M")]) + slot.splice(idx, 1, [input, (s, v) => s.value = v.format("~H:~M")]) field.replaceWith(input); @@ -654,7 +654,7 @@ window.onload = function () { */ let gotodatebtn = document.querySelector("#jump-to .btn"); - let target_href = (new Date).format("%Y-%m-%d") + ".html"; + let target_href = (new Date).format("~Y-~m-~d") + ".html"; let golink = makeElement('a', { className: 'btn', href: target_href, @@ -664,7 +664,7 @@ window.onload = function () { gotodatebtn.replaceWith(golink); document.querySelector("#jump-to input[name='date']").onchange = function () { - let date = this.valueAsDate.format("%Y-%m-%d"); + let date = this.valueAsDate.format("~Y-~m-~d"); console.log(date); golink.href = date + ".html"; } @@ -740,7 +740,7 @@ function format_date(date, str) { case 'Z': if (date.utc) outstr += 'Z'; break; } fmtmode = false; - } else if (str[i] == '%') { + } else if (str[i] == '~') { fmtmode = true; } else { outstr += str[i]; @@ -785,9 +785,9 @@ function bind_properties (el, wide_event=false) { for (let s of el.querySelectorAll(field + " > :not(parameters)")) { switch (s.tagName) { case 'date': - lst.push([s, (s, v) => s.innerHTML = v.format("%Y-%m-%d")]); break; + lst.push([s, (s, v) => s.innerHTML = v.format("~Y-~m-~d")]); break; case 'date-time': - lst.push([s, (s, v) => s.innerHTML = v.format("%Y-%m-%dT%H:%M:%S%Z")]); break; + lst.push([s, (s, v) => s.innerHTML = v.format("~Y-~m-~dT~H:~M:~S~Z")]); break; default: lst.push([s, (s, v) => s.innerHTML = v]); } diff --git a/static/style.scss b/static/style.scss index 1a59173f..3515dd1e 100644 --- a/static/style.scss +++ b/static/style.scss @@ -166,7 +166,7 @@ The sidebar with all the events /* mostly for long links */ word-break: break-word; - article { + .eventtext { border-bottom: 1px solid black; margin-top: 1em; border-left-style: solid; -- cgit v1.2.3