Created
May 11, 2009 18:26
-
-
Save jonmagic/110088 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
class LastDayNextDay | |
def self.last(day) | |
days = { | |
"monday" => 1, | |
"tuesday" => 2, | |
"wednesday" => 3, | |
"thursday" => 4, | |
"friday" => 5, | |
"saturday" => 6, | |
"sunday" => 7 | |
} | |
today_integer = Date.today.cwday | |
last_day_integer = days[day] | |
if today_integer > last_day_integer | |
difference = today_integer - last_day_integer | |
elsif today_integer == last_day_integer | |
difference = 7 | |
else | |
difference = today_integer + 7 - last_day_integer | |
end | |
difference.days.ago.to_date | |
end | |
def self.next(day) | |
days = { | |
"monday" => 1, | |
"tuesday" => 2, | |
"wednesday" => 3, | |
"thursday" => 4, | |
"friday" => 5, | |
"saturday" => 6, | |
"sunday" => 7 | |
} | |
today_integer = Date.today.cwday | |
next_day_integer = days[day] | |
if next_day_integer > today_integer | |
difference = next_day_integer - today_integer | |
elsif next_day_integer == today_integer | |
difference = 7 | |
else | |
difference = next_day_integer + 7 - today_integer | |
end | |
difference.days.from_now.to_date | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment