Class: TimeDifference

Inherits:
Object
  • Object
show all
Defined in:
lib/time_difference.rb

Class Method Summary collapse

Class Method Details

.between(start_time, end_time) ⇒ Object



6
7
8
9
# File 'lib/time_difference.rb', line 6

def self.between(start_time, end_time)
	@time_diff = end_time - start_time
	self
end

.in_each_componentObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/time_difference.rb', line 27

def self.in_each_component
  time_in_each_component = {}
  [:years, :months, :weeks, :days, :hours, :minutes, :seconds].each do |time_component|
    if time_component == :months
      time_in_each_component[time_component] = ((@time_diff/(1.days * 30.42)).round(2)).abs
    else
      time_in_each_component[time_component] = ((@time_diff/1.send(time_component)).round(2)).abs
    end
  end
  time_in_each_component
end

.in_generalObject



39
40
41
42
43
44
45
46
# File 'lib/time_difference.rb', line 39

def self.in_general
	result = {}
 [:years, :months, :weeks, :days, :hours, :minutes, :seconds].each do |time_component|
		result[time_component] = (@time_diff/1.send(time_component)).floor
		@time_diff = (@time_diff - result[time_component].send(time_component))
	end
	result
end