Skip to content

Commit

Permalink
Check period duration to be at least 1 day when using 'at'
Browse files Browse the repository at this point in the history
  • Loading branch information
plashchynski committed Mar 15, 2015
1 parent 6508197 commit 95a237a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/crono/period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def parse_on(on)
end

def parse_at(at)
fail "period should be at least 1 day to use 'at'" if @period < 1.day
case at
when String
time = Time.parse(at)
Expand Down
6 changes: 6 additions & 0 deletions spec/period_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
}.to raise_error("Unknown 'at' format")
end

it 'should raise error when period is less than 1 day' do
expect {
Crono::Period.new(5.hours, at: '15:30')
}.to raise_error("period should be at least 1 day to use 'at'")
end

it 'should return time in relation to last time' do
@period = Crono::Period.new(2.day)
expect(@period.next(since: 1.day.ago)).to be_eql(1.day.from_now)
Expand Down

0 comments on commit 95a237a

Please sign in to comment.