Created
June 18, 2015 22:42
-
-
Save L8D/0be9a20e767513971b76 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
function archiveWeeks(tasks) { | |
return lodash.chain(tasks) | |
.reverse() | |
.groupBy({created_at} => new Date(created_at.getFullYear(), created_at.getMonth(), created_at.getDate())) | |
.map((t, d) => {date: new Date(d), tasks: t}) | |
.groupBy(weekOf) // because I'm lazy | |
.map((d, w) => {week: w, days: d}) | |
.value(); | |
} | |
function weekOf(day) { // pretend it's inline | |
var sunday = new Date(day.date); | |
sunday.setDate(sunday.getDate() - sunday.getDay()); | |
var saturday = new Date(sunday); | |
saturday.setDate(saturday.getDate() + 6); | |
return formatDate(sunday) + ' - ' + formatDate(saturday); | |
} |
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
function archiveWeeks(tasks) { | |
var weeks = lodash.chain(tasks) | |
.reverse() | |
.groupBy(dayOf) | |
.map(toDayObj) | |
.groupBy(weekOf) | |
.map(toWeekObj) | |
.value(); | |
return weeks; | |
} | |
function dayOf(task) { | |
var time = task.get('created_at'); | |
return new Date(time.getFullYear(), time.getMonth(), time.getDate()); | |
} | |
function weekOf(day) { | |
var sunday = new Date(day.date); | |
sunday.setDate(sunday.getDate() - sunday.getDay()); | |
var saturday = new Date(sunday); | |
saturday.setDate(saturday.getDate() + 6); | |
return formatDate(sunday) + ' - ' + formatDate(saturday); | |
} | |
function toDayObj(tasks, day) { | |
return { | |
date: new Date(day), | |
tasks: tasks | |
}; | |
} | |
function toWeekObj(days, week) { | |
return { | |
date: week, | |
days: days, | |
}; | |
} | |
function formatDay(date) { | |
return dateformat(date, 'dddd, mmmm dS'); | |
} | |
function formatDate(date) { | |
return dateformat(date, 'mmmm dS'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment