mirror of
https://github.com/plashchynski/crono.git
synced 2026-07-05 12:31:34 +02:00
Check period duration to be at least 1 day when using 'at'
This commit is contained in:
@@ -47,6 +47,7 @@ module Crono
|
|||||||
end
|
end
|
||||||
|
|
||||||
def parse_at(at)
|
def parse_at(at)
|
||||||
|
fail "period should be at least 1 day to use 'at'" if @period < 1.day
|
||||||
case at
|
case at
|
||||||
when String
|
when String
|
||||||
time = Time.parse(at)
|
time = Time.parse(at)
|
||||||
|
|||||||
@@ -78,6 +78,12 @@ describe Crono::Period do
|
|||||||
}.to raise_error("Unknown 'at' format")
|
}.to raise_error("Unknown 'at' format")
|
||||||
end
|
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
|
it 'should return time in relation to last time' do
|
||||||
@period = Crono::Period.new(2.day)
|
@period = Crono::Period.new(2.day)
|
||||||
expect(@period.next(since: 1.day.ago)).to be_eql(1.day.from_now)
|
expect(@period.next(since: 1.day.ago)).to be_eql(1.day.from_now)
|
||||||
|
|||||||
Reference in New Issue
Block a user