Skip to content

Commit

Permalink
make dates more relatable
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsteward committed Dec 22, 2022
1 parent bd39b62 commit 80bdefb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions modules/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ function getCurrentExhibitions(callback) {
fetch(url)
.then(response => response.json())
.then(results => {
let now = new Date();
now = new Date(now.toUTCString());

results['records'].forEach(r => {
let enddate = new Date(r['enddate']);
enddate.setDate(enddate.getDate() + 1);
const diff = enddate.getTime() - now.getTime();
r.days_left = Math.round(diff/86400000);
r.enddate_long = enddate.toLocaleDateString('en-US', {weekday: 'long', year: "numeric", month: "long", day: "numeric",});
});

callback(null, results['records']);
});
}
Expand All @@ -100,6 +111,17 @@ function getUpcomingExhibitions(callback) {
fetch(url)
.then(response => response.json())
.then(results => {
let now = new Date();
now = new Date(now.toUTCString());

results['records'].forEach(r => {
let begindate = new Date(r['begindate']);
begindate.setDate(begindate.getDate() + 1);
const diff = begindate.getTime() - now.getTime();
r.days_until_opening = Math.round(diff/86400000);
r.begindate_long = begindate.toLocaleDateString('en-US', {weekday: 'long', year: "numeric", month: "long", day: "numeric",});
});

callback(null, results['records']);
});
}
Expand Down
4 changes: 2 additions & 2 deletions views/production.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<ul class="list-group">
{{#if apistats.exhibitions.current.length}}
{{#each apistats.exhibitions.current}}
<li class="list-group-item"><a href="{{url}}">{{title}}</a> <br/><span class="figure-caption">closes on {{enddate}}</span></li>
<li class="list-group-item"><a href="{{url}}">{{title}}</a> <br/><span class="figure-caption">closes on {{enddate_long}} <br/>{{days_left}} days left</span></li>
{{/each}}
{{else}}
<li class="list-group-item">No current exhibitions</li>
Expand All @@ -109,7 +109,7 @@
<ul class="list-group">
{{#if apistats.exhibitions.upcoming.length}}
{{#each apistats.exhibitions.upcoming}}
<li class="list-group-item"><a href="{{url}}">{{title}}</a> <br/><span class="figure-caption">opens on {{begindate}}</span></li>
<li class="list-group-item"><a href="{{url}}">{{title}}</a> <br/><span class="figure-caption">opens on {{begindate_long}} <br/>{{days_until_opening}} days until opening</span></li>
{{/each}}
{{else}}
<li class="list-group-item">No upcoming exhibitions</li>
Expand Down

0 comments on commit 80bdefb

Please sign in to comment.