Skip to content

Instantly share code, notes, and snippets.

@oelbrenner
Forked from radar/proximity.rb
Created April 7, 2012 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oelbrenner/2331964 to your computer and use it in GitHub Desktop.
Save oelbrenner/2331964 to your computer and use it in GitHub Desktop.
class Date
def to_words
if self == Date.today
"Today"
elsif self <= Date.today - 1
if self == Date.today - 1
"Yesterday"
elsif ((Date.today - 7)..(Date.today - 1)).include?(self)
"Last #{self.strftime("%A")}"
elsif ((Date.today - 14)..(Date.today - 8)).include?(self)
"Two #{self.strftime("%A")}s ago"
elsif ((Date.today - 21)..(Date.today - 15)).include?(self)
"Three #{self.strftime("%A")}s ago"
elsif ((Date.today - 29)..(Date.today - 22)).include?(self)
"Four #{self.strftime("%A")}s ago"
elsif Date.today - 30 < self
"More than a month ago"
end
else
if self == Date.today + 1
"Tomorrow"
elsif ((Date.today + 1)..(Date.today + 6)).include?(self)
"This coming #{self.strftime("%A")}"
elsif ((Date.today + 7)..(Date.today + 14)).include?(self)
"Next #{self.strftime("%A")}s away"
elsif ((Date.today + 15)..(Date.today + 21)).include?(self)
"Two #{self.strftime("%A")}s away"
elsif ((Date.today + 22)..(Date.today + 29)).include?(self)
"Three #{self.strftime("%A")}s away"
elsif Date.today + 30 > self
"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