Mercurial > code > home > repos > front-door-display
comparison 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 |
comparison
equal
deleted
inserted
replaced
20:e8c90d893919 | 21:a90cb6927c7d |
---|---|
10 constructor(private store: Store, private graph: Term, public uri: Quad_Subject) {} | 10 constructor(private store: Store, private graph: Term, public uri: Quad_Subject) {} |
11 get title(): string { | 11 get title(): string { |
12 return getLiteral(this.store, this.graph, this.uri, namedNode(EV + "title"), "(unnamed)"); | 12 return getLiteral(this.store, this.graph, this.uri, namedNode(EV + "title"), "(unnamed)"); |
13 } | 13 } |
14 get start(): string { | 14 get start(): string { |
15 return getLiteral(this.store, this.graph, this.uri, namedNode(EV + "start"), null); | 15 var ret = getLiteral(this.store, this.graph, this.uri, namedNode(EV + "start"), null); |
16 if (ret == null || ret === "") { | |
17 ret = getLiteral(this.store, this.graph, this.uri, namedNode(EV + "startDate"), null); | |
18 } | |
19 return ret; | |
16 } | 20 } |
17 get feed(): NamedNode { | 21 get calendar(): NamedNode { |
22 // todo: broken- it's now (calendar, :event, event) | |
18 return namedNode(getLiteral(this.store, this.graph, this.uri, namedNode(EV + "feed"), null)); | 23 return namedNode(getLiteral(this.store, this.graph, this.uri, namedNode(EV + "feed"), null)); |
19 } | 24 } |
20 shortDate(): TemplateResult { | 25 shortDate(): TemplateResult { |
21 const t = parseISO(this.start); | 26 const t = parseISO(this.start); |
22 return html`<span class="d">${format(t, "EEE, MMM d,")}</span> <span class="t">${format(t, "HH:mm")}</span>`; | 27 return html`<span class="d">${format(t, "EEE, MMM d,")}</span> <span class="t">${format(t, "HH:mm")}</span>`; |
23 } | 28 } |
24 inHowLong(): TemplateResult { | 29 inHowLong(): TemplateResult { |
25 // returns start()-now, like '5 days' | 30 // returns start()-now, like 'In 5 days' |
26 const t = parseISO(this.start).valueOf(); | 31 const t = parseISO(this.start).valueOf(); |
27 const now = Date.now(); | 32 const now = Date.now(); |
28 const daysAway = (t - now) / 1000 / 86400; | 33 const daysAway = (t - now) / 1000 / 86400; |
34 if (daysAway < 0) { | |
35 return html`<span class="until until-2d">NOW</span>`; | |
36 } | |
29 const prec = daysAway < 2 ? 1 : 0; | 37 const prec = daysAway < 2 ? 1 : 0; |
30 const cls = "until " + (daysAway < 2 ? "until-2d" : daysAway < 7 ? "until-7d" : daysAway < 30 ? "until-1mo" : ""); | 38 const cls = "until " + (daysAway < 2 ? "until-2d" : daysAway < 7 ? "until-7d" : daysAway < 30 ? "until-1mo" : ""); |
31 return html`<span class="${cls}">${daysAway.toFixed(prec)} days</span>`; | 39 return html`In <span class="${cls}">${daysAway.toFixed(prec)} days</span>`; |
32 } | 40 } |
33 show(): boolean { | 41 show(): boolean { |
34 const now = new Date(); | 42 const now = new Date(); |
35 const t = parseISO(this.start); | 43 const t = parseISO(this.start); |
36 | 44 |
38 let end = endOfToday(); | 46 let end = endOfToday(); |
39 if (isAfter(now, addHours(startOfToday(), 18))) { | 47 if (isAfter(now, addHours(startOfToday(), 18))) { |
40 end = endOfTomorrow(); | 48 end = endOfTomorrow(); |
41 } | 49 } |
42 | 50 |
43 return isWithinInterval(t, { start, end }) && !hideTitles.has(this.title) && !hideFeeds.has(this.feed.value); | 51 return isWithinInterval(t, { start, end }) && !hideTitles.has(this.title) && !hideFeeds.has(this.calendar.value); |
44 } | 52 } |
45 } | 53 } |