Class: EnglishTime

Inherits:
Object
  • Object
show all
Defined in:
lib/svnx/util/englishtime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time) ⇒ EnglishTime

Returns a new instance of EnglishTime.



10
11
12
# File 'lib/svnx/util/englishtime.rb', line 10

def initialize time
  @time = time
end

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



8
9
10
# File 'lib/svnx/util/englishtime.rb', line 8

def time
  @time
end

Instance Method Details

#agoObject



14
15
16
# File 'lib/svnx/util/englishtime.rb', line 14

def ago
  since Time.new, "ago"
end

#earlier(totime) ⇒ Object



18
19
20
# File 'lib/svnx/util/englishtime.rb', line 18

def earlier totime
  since totime, "earlier"
end

#since(totime, name) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/svnx/util/englishtime.rb', line 22

def since totime, name
  diff = totime - @time
  seconds = diff.to_i
  if units = TimeUtil.new.to_units(seconds)
    sprintf "%s %s %s (%s)", units.first, units.last, name, @time.strftime("%m/%d %H:%M")
  else
    @time.strftime "%Y/%m/%d %H:%M"
  end
end