Skip to content

Commit

Permalink
made getting single day/lib more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
szendeh-mit committed Jan 12, 2015
1 parent a698b1b commit 71bd598
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 5 additions & 1 deletion js/libhours.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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];
}
7 changes: 3 additions & 4 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 71bd598

Please sign in to comment.