Skip to content

Instantly share code, notes, and snippets.

@tobi
Created July 14, 2011 02:34
Show Gist options
  • Select an option

  • Save tobi/1081845 to your computer and use it in GitHub Desktop.

Select an option

Save tobi/1081845 to your computer and use it in GitHub Desktop.

Revisions

  1. Tobias Lütke created this gist Jul 14, 2011.
    26 changes: 26 additions & 0 deletions mess.coffee
    Original 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]
    }