From 95a237aeb5cbdd47728f56975c74c167980c76a6 Mon Sep 17 00:00:00 2001 From: Dzmitry Plashchynski Date: Sun, 15 Mar 2015 09:56:18 +0200 Subject: [PATCH] Check period duration to be at least 1 day when using 'at' --- lib/crono/period.rb | 1 + spec/period_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+) 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)