diff --git a/lib/crono/period.rb b/lib/crono/period.rb index 40210c1..31a99f3 100644 --- a/lib/crono/period.rb +++ b/lib/crono/period.rb @@ -47,6 +47,7 @@ module Crono 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) diff --git a/spec/period_spec.rb b/spec/period_spec.rb index 2a34c8a..bb7fa57 100644 --- a/spec/period_spec.rb +++ b/spec/period_spec.rb @@ -78,6 +78,12 @@ describe Crono::Period do }.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)