class Time
Constants
- DAYS_IN_YEAR
- HUMAN_TIMES
- SECONDS_IN_DAY
- SECONDS_IN_HOUR
- SECONDS_IN_MINUTE
- SECONDS_IN_MONTH
- SECONDS_IN_WEEK
- SECONDS_IN_YEAR
Public Instance Methods
relative(t0 = Time.now)
click to toggle source
# File lib/git_tools/extensions/time.rb, line 23 def relative(t0 = Time.now) dt = self - t0 if dt < 0 tense = 'ago' dt = dt.abs - 1 else tense = 'from now' end if dt < SECONDS_IN_MINUTE return 'now' else HUMAN_TIMES.each do |time| seconds = time[0] limit = time[1] time_unit = time[2] if dt < seconds * limit return "{time} #{time_unit} #{tense}".multi_gsub!(:time => (dt/seconds).ceil.to_i) end end # Above the higest limit "over a year #{tense}" end end