lib/time_sheet/time/entry.rb in time-sheet-0.6.0 vs lib/time_sheet/time/entry.rb in time-sheet-0.6.1

- old
+ new

@@ -5,11 +5,11 @@ def initialize(data) @data = data end - attr_accessor :prev, :next + attr_accessor :prev, :next, :exception, :data def project @data['project'] ||= self.prev.project end @@ -30,11 +30,10 @@ date.year, date.month, date.day, @data['start'].hour, @data['start'].min ) end - def end ends_at = @data['end'] || (self.next ? self.next.start : self.class.now) @end ||= Time.mktime( date.year, date.month, date.day, @@ -94,11 +93,28 @@ (!from || from <= self.start) && (!to || to >= self.end) end def valid? - (duration > 0) && - ((self.start < self.end) || !self.next) + valid! + true + rescue TimeSheet::Time::Exception => e + self.exception = e + false + end + + def valid! + if !@data['start'] + raise TimeSheet::Time::Exception.new('time entry has no start') + end + + if duration <= 0 + raise TimeSheet::Time::Exception.new('time entry duration is 0 or less') + end + + if (self.start >= self.end) && self.next + raise TimeSheet::Time::Exception.new('time entry has no end') + end end def to_row [date, start, self.end, duration.to_i, project, activity, description] end \ No newline at end of file