Skip to content

Instantly share code, notes, and snippets.

@lachie
Forked from radar/proximity.rb
Created August 7, 2008 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lachie/4367 to your computer and use it in GitHub Desktop.
Save lachie/4367 to your computer and use it in GitHub Desktop.
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