mirror of
https://github.com/plashchynski/crono.git
synced 2026-04-27 11:17:15 +02:00
Able to specify minutes for hour-based schedule. Closing #26
This commit is contained in:
@@ -49,7 +49,10 @@ 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
|
if @period < 1.day && (at.is_a? String || at[:hour])
|
||||||
|
fail "period should be at least 1 day to use 'at' with specified hour"
|
||||||
|
end
|
||||||
|
|
||||||
case at
|
case at
|
||||||
when String
|
when String
|
||||||
time = Time.parse(at)
|
time = Time.parse(at)
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ describe Crono::Period do
|
|||||||
expect(@period.next(since: 2.days.ago).to_s).to be_eql(Time.now.to_s)
|
expect(@period.next(since: 2.days.ago).to_s).to be_eql(Time.now.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return the time 2 days from now' do
|
it 'should return time 2 days from now' do
|
||||||
@period = Crono::Period.new(2.day)
|
@period = Crono::Period.new(2.day)
|
||||||
expect(@period.next.to_s).to be_eql(2.days.from_now.to_s)
|
expect(@period.next.to_s).to be_eql(2.days.from_now.to_s)
|
||||||
end
|
end
|
||||||
@@ -80,7 +80,7 @@ describe Crono::Period do
|
|||||||
it 'should raise error when period is less than 1 day' do
|
it 'should raise error when period is less than 1 day' do
|
||||||
expect {
|
expect {
|
||||||
Crono::Period.new(5.hours, at: '15:30')
|
Crono::Period.new(5.hours, at: '15:30')
|
||||||
}.to raise_error("period should be at least 1 day to use 'at'")
|
}.to raise_error("period should be at least 1 day to use 'at' with specified hour")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return time in relation to last time' do
|
it 'should return time in relation to last time' do
|
||||||
@@ -95,5 +95,21 @@ describe Crono::Period do
|
|||||||
expect(@period.next.utc.to_s).to be_eql(Time.now.change(at).utc.to_s)
|
expect(@period.next.utc.to_s).to be_eql(Time.now.change(at).utc.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'in hourly basis' do
|
||||||
|
it 'should return next hour minutes if current hour minutes passed' do
|
||||||
|
Timecop.freeze(Time.now.beginning_of_hour.advance(minutes: 20)) do
|
||||||
|
@period = Crono::Period.new(1.hour, at: { min: 15 })
|
||||||
|
expect(@period.next.utc.to_s).to be_eql 1.hour.from_now.beginning_of_hour.advance(minutes: 15).utc.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return current hour minutes if current hour minutes not passed yet' do
|
||||||
|
Timecop.freeze(Time.now.beginning_of_hour.advance(minutes: 10)) do
|
||||||
|
@period = Crono::Period.new(1.hour, at: { min: 15 })
|
||||||
|
expect(@period.next.utc.to_s).to be_eql Time.now.beginning_of_hour.advance(minutes: 15).utc.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user