Is anyone aware of a gem, method, or code snippet that will convert datetime values into sometime more human-friendly without having to create a series of rules or put a bun
This is a little hack, totally unfinished and inelegant. But Ruby/Rails is so awesome with dates, and ranges are so perfect, maybe if you don't find the gem, something like this will get you started:
module HumanDate
def date_difference_for_people (from, to)
seconds_in_day = 24 * 60 * 60
days_difference = ((to - from)/seconds_in_day).round
case days_difference
when -1
"yesterday"
when 0
"today"
when 1
"tomorrow"
when 2..days_left_in_week
"this #{day_name(difference)}"
when (days_left_in_week + 1)..(days_left_in_week + 7)
"next week"
when (days_left_in_week + 8)..days_left_in_month
"later this month"
else
"later -- how much left to you :-)"
end
end
def day_name(days_from_now)
days_from_now.days_from_now.strftime("%A")
end
def days_left_in_month
Time.now.end_of_month.day - Time.now.day
end
def days_left_in_week
Time.now.end_of_week.day - Time.now.day
end
end