Created
July 14, 2011 02:34
-
-
Save tobi/1081845 to your computer and use it in GitHub Desktop.
Quick access to useful timespans for reporting
This file contains hidden or 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
selectors: -> | |
today = new Date() | |
today.setMinutes(0) | |
today.setHours(0) | |
today.setSeconds(0) | |
day = 1000*60*60*24 | |
yesterday = today - day | |
lastSunday = today - today.getDay() * day | |
firstOfMonth = (date) -> | |
date - day * new Date(date).getDate() + day | |
beginningOfMonth = firstOfMonth(today) | |
endOfMonth = firstOfMonth(beginningOfMonth + 31 * day) - day | |
endOfLastMonth = beginningOfMonth - day | |
beginningOfLastMonth = firstOfMonth(endOfLastMonth) | |
return { | |
"Yesterday": [yesterday, yesterday], | |
"Last 7 days": [yesterday - 7 * day, yesterday] | |
"This Week": [lastSunday, lastSunday + 7 * day] | |
"Last Week": [lastSunday - 7 * day, lastSunday] | |
"This Month": [beginningOfMonth, endOfMonth] | |
"Last Month": [beginningOfLastMonth, endOfLastMonth] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment