Add validation
This commit is contained in:
@ -4,4 +4,7 @@ module Dayoff
|
||||
|
||||
class StartedRecordNotFound < Exception
|
||||
end
|
||||
|
||||
class AlreadyStarted < Exception
|
||||
end
|
||||
end
|
||||
|
@ -35,6 +35,9 @@ module Dayoff
|
||||
end
|
||||
|
||||
def start(time : Time) : Nil
|
||||
if started_point
|
||||
raise AlreadyStarted.new
|
||||
end
|
||||
@wrecords.each do |wr|
|
||||
if time <= wr.start || time <= wr.finish!
|
||||
raise CrossedTimeSpan.new
|
||||
@ -46,7 +49,7 @@ module Dayoff
|
||||
end
|
||||
|
||||
def finish(time : Time) : Nil
|
||||
started = @wrecords.find { |x| x.started? }
|
||||
started = started_point
|
||||
if started.nil?
|
||||
raise StartedRecordNotFound.new
|
||||
end
|
||||
@ -59,5 +62,9 @@ module Dayoff
|
||||
worked = get_work_hours on_time
|
||||
planned - worked
|
||||
end
|
||||
|
||||
private def started_point
|
||||
@wrecords.find { |x| x.started? }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user