From 71bd5984601fcf9dcb04fb00dd4bcb3120d53dee Mon Sep 17 00:00:00 2001 From: szendeh Date: Mon, 12 Jan 2015 15:11:35 -0500 Subject: [PATCH] made getting single day/lib more efficient --- js/libhours.js | 6 +++++- js/main.js | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/js/libhours.js b/js/libhours.js index 5276f34..3877b1e 100644 --- a/js/libhours.js +++ b/js/libhours.js @@ -1,6 +1,6 @@ // takes in the complete data object from the google doc/json file(s) // and a js date object -// returns a hash (object) of librarys +// returns a hash (object) of libraries // library object key is the library name // library object value is an array of 7 "hours" strings // each of the 7 corresponds to a day-of-the-week (0=monday, 6=sunday) @@ -132,5 +132,9 @@ function buildCompleteHoursObject(data, date) { function buildSingleHoursObject(data, date, libname) { var completeHoursObject = buildCompleteHoursObject(data, date); + return completeHoursObject[libname][moment(date).isoWeekday()-1]; +} + +function getSingleHoursObject(completeHoursObject, date, libname) { return completeHoursObject[libname][moment(date).isoWeekday()-1]; } \ No newline at end of file diff --git a/js/main.js b/js/main.js index 4431115..443036a 100644 --- a/js/main.js +++ b/js/main.js @@ -3,14 +3,13 @@ function processHours(data, tabletop) { // get page_date however you want, I'm just defaulting to new Date var date = new Date(2014, 11, 31); - // all libs/entire week + // only build the hours object once var completeHoursObject = buildCompleteHoursObject(data, date); - // do something with the json object. for now, I console log it. console.log(completeHoursObject); - // single lib/one day - var singleHoursObject = buildSingleHoursObject(data, date, 'Barker Library') + // extract the hours for a particular date/lib from the complete object this way + var singleHoursObject = getSingleHoursObject(completeHoursObject, date, 'Barker Library') console.log(singleHoursObject); }