diff --git a/lib/time_difference.rb b/lib/time_difference.rb index 73705cf..bc06f9e 100644 --- a/lib/time_difference.rb +++ b/lib/time_difference.rb @@ -7,8 +7,8 @@ class TimeDifference TIME_COMPONENTS = [:years, :months, :weeks, :days, :hours, :minutes, :seconds] - def self.between(start_time, end_time) - new(start_time, end_time) + def self.between(start_time, end_time, abs=true) + new(start_time, end_time, abs) end def in_years @@ -78,12 +78,13 @@ def humanize end private - - def initialize(start_time, end_time) + + def initialize(start_time, end_time, abs=true) start_time = time_in_seconds(start_time) end_time = time_in_seconds(end_time) - @time_diff = (end_time - start_time).abs + @time_diff = (end_time - start_time) + @time_diff = @time_diff.abs if abs end def time_in_seconds(time)