From e4e709bd728ef14b84fb33a53fcd587f506f53d4 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Wed, 9 Nov 2011 15:14:09 +0100 Subject: [PATCH] Changed period logic, use update_at attribute if there are no time entries. --- stoptime.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index b737779..ee25146 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -78,7 +78,7 @@ module StopTime::Models def bill_period bte = billable_time_entries if bte.empty? - [nil, nil] + [updated_at, updated_at] else [bte.first.start, bte.last.end] end @@ -113,19 +113,18 @@ module StopTime::Models belongs_to :customer def summary - # FIXME: ensure that month is a DateTime/Time object. summ = {} tasks.each { |task| summ[task.name] = task.summary } return summ end def period - p = [Time.now, Time.now] + return [updated_at, updated_at] if tasks.empty? + p = tasks.first.bill_period tasks.each do |task| tp = task.bill_period - p tp - p[0] = tp[0] if !tp[0].nil? and tp[0] < p[0] - p[1] = tp[1] if !tp[1].nil? and tp[1] > p[1] + p[0] = tp[0] if tp[0] < p[0] + p[1] = tp[1] if tp[1] > p[1] end return p end