lib/toggl/worktime/merger.rb in toggl-worktime-0.3.0 vs lib/toggl/worktime/merger.rb in toggl-worktime-0.3.1

- old
+ new

@@ -6,11 +6,11 @@ module Worktime # Time-entries merger class Merger attr_reader :total_time - ONE_DAY_MINUTES = 24 * 60 + ONE_MINUTE_SECONDS = 60 def initialize(time_entries, config) @time_entries = time_entries @config = config @current_start = nil @@ -26,14 +26,16 @@ if continuing(start) @current_stop = stop next end work_time << [@current_start, @current_stop] + @total_time += @current_stop - @current_start @current_start = start @current_stop = stop end work_time << [@current_start, @last_stop] + @total_time += @current_stop - @current_start work_time end def time_entries_each zone_offset = Toggl::Worktime::Time.zone_offset(@config.timezone) @@ -43,24 +45,24 @@ @last_stop = stop @current_start = start if @current_start.nil? @current_stop = stop if @current_stop.nil? if start.nil? || stop.nil? warn 'start or stop time is nil: total time may be incomplete' - else - @total_time += stop - start end yield [start, stop] end end def parse_date(date, zone_offset) return nil if date.nil? + ::Time.parse(date).getlocal(zone_offset) end def continuing(start) return true if @current_stop.nil? - interval = (start - @current_stop) * ONE_DAY_MINUTES + + interval = (start - @current_stop) / ONE_MINUTE_SECONDS @continuing = interval < @config.working_interval_min end end end end