Class: TimeDifference
Instance Method Summary collapse
- #humanize ⇒ Object
-
#initialize(start_date, end_date = nil, klass = nil) ⇒ TimeDifference
constructor
A new instance of TimeDifference.
Constructor Details
#initialize(start_date, end_date = nil, klass = nil) ⇒ TimeDifference
Returns a new instance of TimeDifference.
33 34 35 36 37 38 39 40 |
# File 'lib/common/time_difference.rb', line 33 def initialize start_date, end_date = nil, klass = nil unless end_date @end_date = start_date @start_date = Time.now end @klass = klass end |
Instance Method Details
#humanize ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/common/time_difference.rb', line 42 def humanize diff = (@start_date.to_i - @end_date.to_i).abs if @klass == Date && diff < TIMES[2][1] return locale(:today) # @start_date < @end_date ? locale(:in_few_econds) : locale(:just_happend) end TIMES.each do |(key, ref)| value = diff / ref return part(key, value) if value > 0 end @start_date < @end_date ? locale(:in_few_econds) : locale(:just_happend) end |