Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Forked from jdivock/fuckingDates.js
Last active August 29, 2015 14:07
Show Gist options
  • Save ethagnawl/3525c5d8923ecd1159f8 to your computer and use it in GitHub Desktop.
Save ethagnawl/3525c5d8923ecd1159f8 to your computer and use it in GitHub Desktop.
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