Created
April 16, 2016 05:45
-
-
Save AlexVKO/76acd01b758f483670b29a8d4487dca4 to your computer and use it in GitHub Desktop.
A cool method to display Date time
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
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