Method: Time#relative_date
- Defined in:
- lib/doing/time.rb
#relative_date ⇒ String
Format time as a relative date. Dates from today get just a time, from the last week get a time and day, from the last year get a month/day/time, and older entries get month/day/year/time
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/doing/time.rb', line 13 def relative_date if self > Date.today.to_time strftime(Doing.setting('shortdate_format.today', '%_I:%M%P', exact: true)) elsif self > (Date.today - 6).to_time strftime(Doing.setting('shortdate_format.this_week', '%a %_I:%M%P', exact: true)) elsif year == Date.today.year || (year + 1 == Date.today.year && month > Date.today.month) strftime(Doing.setting('shortdate_format.this_month', '%m/%d %_I:%M%P', exact: true)) else strftime(Doing.setting('shortdate_format.older', '%m/%d/%y %_I:%M%P', exact: true)) end end |