Skip to content

Instantly share code, notes, and snippets.

@AlexVKO
Created April 16, 2016 05:45
Show Gist options
  • Save AlexVKO/76acd01b758f483670b29a8d4487dca4 to your computer and use it in GitHub Desktop.
Save AlexVKO/76acd01b758f483670b29a8d4487dca4 to your computer and use it in GitHub Desktop.
A cool method to display Date time
def scheduled_at_in_words
time = object.scheduled_at
st = Time.now.beginning_of_day
nd = Time.now.end_of_day
case
when time.between?(st + 1.day, nd + 1.day)
"Tomorrow #{time.strftime('%H:%M')}"
when time.between?(st, nd)
"Today #{time.strftime('%H:%M')}"
when time.between?(st - 1.day, nd - 1.day)
"Yesterday #{time.strftime('%H:%M')}"
when time.between?(st - 6.day, nd - 2.day)
time.strftime('%a %H:%M')
else
time.strftime('%b-%d %H:%M')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment