From 80bdefbd73116f1ed8dc23f8d382eaf3d015be82 Mon Sep 17 00:00:00 2001 From: Jeff Steward Date: Thu, 22 Dec 2022 16:43:14 -0500 Subject: [PATCH] make dates more relatable --- modules/data.js | 22 ++++++++++++++++++++++ views/production.hbs | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/data.js b/modules/data.js index 083e27a..bb7ebcf 100644 --- a/modules/data.js +++ b/modules/data.js @@ -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']); }); } @@ -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']); }); } diff --git a/views/production.hbs b/views/production.hbs index 4d4a8e9..b3408e4 100644 --- a/views/production.hbs +++ b/views/production.hbs @@ -96,7 +96,7 @@