-
-
Save radar/4503 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 Date | |
def to_words | |
today = Date.today | |
case self | |
when today | |
"Today" | |
when today - 1 | |
"Yesterday" | |
when today + 1 | |
"Tomorrow" | |
when (today - 7)..(today - 1) | |
"Last #{strftime("%A")}" | |
when (today + 1)..(today + 7) | |
"Next #{strftime("%A")}" | |
when (today + 8)..(today + 14) | |
"Two #{strftime("%A")}s away" | |
when (today - 14)..(today - 8) | |
"Two #{strftime("%A")}s ago" | |
when (today + 15)..(today + 21) | |
"Three #{strftime("%A")}s away" | |
when (today - 21)..(today - 15) | |
"Three #{strftime("%A")}s ago" | |
when (today + 22)..(today + 29) | |
"Four #{strftime("%A")}s away" | |
when (today - 29)..(today - 22) | |
"Four #{strftime("%A")}s ago" | |
else | |
if today - 30 > self | |
"More than a month ago" | |
else | |
"More than a month in the future" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment