-
-
Save ethagnawl/3525c5d8923ecd1159f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var times = { | |
Schedule: { | |
"2014-09-26T00:00:00": [1,23], | |
"2014-09-27T00:00:00": [9,14] | |
} | |
}; | |
function formatHour(hour) { | |
return hour > 12 ? | |
[hour - 12, '00 PM'].join(':') : | |
[hour, '00 AM'].join(':'); | |
} | |
function formatDate(date, hour) { | |
return new Date(date.setHours(date.getHours() + hour)).toISOString(); | |
} | |
function constructDateObject(date, hour) { | |
return { | |
label: formatHour(hour), | |
value: formatDate(new Date(date), hour) | |
}; | |
} | |
var foo = _.map(times.Schedule, function (hours, date) { | |
return _.map(hours, _.partial(constructDateObject, date)); | |
}); | |
console.log(JSON.stringify(foo)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment