Skip to content

Instantly share code, notes, and snippets.

@tsommer
Created May 26, 2011 03:35

Revisions

  1. Thomas Sommer revised this gist May 26, 2011. No changes.
  2. Thomas Sommer renamed this gist May 26, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. Thomas Sommer created this gist May 26, 2011.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    require 'time'

    DAYS = {
    "Sun" => 0,
    "Mon" => 1,
    "Tue" => 2,
    "Wed" => 3,
    "Thu" => 4,
    "Fri" => 5,
    "Sat" => 6
    }
    DAY_IN_SECONDS = 24 * 60 * 60

    def date_for_day(day)
    now = Time.new

    difference = DAYS[day] - now.wday
    difference += 7 if difference < 0

    now + difference * DAY_IN_SECONDS
    end

    p "Thu: " + date_for_day('Thu').to_s
    p "Fri: " + date_for_day('Fri').to_s
    p "Sat: " + date_for_day('Sat').to_s
    p "Sun: " + date_for_day('Sun').to_s
    p "Mon: " + date_for_day('Mon').to_s
    p "Tue: " + date_for_day('Tue').to_s
    p "Wed: " + date_for_day('Wed').to_s