Created
July 14, 2011 02:34
-
-
Save tobi/1081845 to your computer and use it in GitHub Desktop.
Revisions
-
Tobias Lütke created this gist
Jul 14, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ 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] }