Mercurial > code > home > repos > front-door-display
diff src/DisplayEvent.ts @ 21:a90cb6927c7d default tip
fix countdown queries. Display "now" instead of "In -0.4 hours"
author | drewp@bigasterisk.com |
---|---|
date | Sat, 07 Sep 2024 17:47:36 -0700 |
parents | 20d1fa4250c0 |
children |
line wrap: on
line diff
--- a/src/DisplayEvent.ts Mon Aug 26 16:17:49 2024 -0700 +++ b/src/DisplayEvent.ts Sat Sep 07 17:47:36 2024 -0700 @@ -12,9 +12,14 @@ return getLiteral(this.store, this.graph, this.uri, namedNode(EV + "title"), "(unnamed)"); } get start(): string { - return getLiteral(this.store, this.graph, this.uri, namedNode(EV + "start"), null); + var ret = getLiteral(this.store, this.graph, this.uri, namedNode(EV + "start"), null); + if (ret == null || ret === "") { + ret = getLiteral(this.store, this.graph, this.uri, namedNode(EV + "startDate"), null); + } + return ret; } - get feed(): NamedNode { + get calendar(): NamedNode { + // todo: broken- it's now (calendar, :event, event) return namedNode(getLiteral(this.store, this.graph, this.uri, namedNode(EV + "feed"), null)); } shortDate(): TemplateResult { @@ -22,13 +27,16 @@ return html`<span class="d">${format(t, "EEE, MMM d,")}</span> <span class="t">${format(t, "HH:mm")}</span>`; } inHowLong(): TemplateResult { - // returns start()-now, like '5 days' + // returns start()-now, like 'In 5 days' const t = parseISO(this.start).valueOf(); const now = Date.now(); const daysAway = (t - now) / 1000 / 86400; + if (daysAway < 0) { + return html`<span class="until until-2d">NOW</span>`; + } const prec = daysAway < 2 ? 1 : 0; const cls = "until " + (daysAway < 2 ? "until-2d" : daysAway < 7 ? "until-7d" : daysAway < 30 ? "until-1mo" : ""); - return html`<span class="${cls}">${daysAway.toFixed(prec)} days</span>`; + return html`In <span class="${cls}">${daysAway.toFixed(prec)} days</span>`; } show(): boolean { const now = new Date(); @@ -40,6 +48,6 @@ end = endOfTomorrow(); } - return isWithinInterval(t, { start, end }) && !hideTitles.has(this.title) && !hideFeeds.has(this.feed.value); + return isWithinInterval(t, { start, end }) && !hideTitles.has(this.title) && !hideFeeds.has(this.calendar.value); } }