mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-07 06:40:07 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b627275d8 | ||
|
|
00d5c777dd | ||
|
|
c28a0bbc8a | ||
|
|
45c22ee6ba | ||
|
|
2ac14113b6 |
20
Gemfile.lock
20
Gemfile.lock
@@ -1,17 +1,13 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
crono (0.8.9)
|
||||
activejob (~> 4.0)
|
||||
crono (0.9.0)
|
||||
activerecord (~> 4.0)
|
||||
activesupport (~> 4.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
activejob (4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
globalid (>= 0.3.0)
|
||||
activemodel (4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
builder (~> 3.1)
|
||||
@@ -27,18 +23,16 @@ GEM
|
||||
tzinfo (~> 1.1)
|
||||
arel (6.0.0)
|
||||
builder (3.2.2)
|
||||
byebug (4.0.5)
|
||||
byebug (5.0.0)
|
||||
columnize (= 0.9.0)
|
||||
columnize (0.9.0)
|
||||
diff-lcs (1.2.5)
|
||||
globalid (0.3.5)
|
||||
activesupport (>= 4.1.0)
|
||||
haml (4.0.6)
|
||||
tilt
|
||||
i18n (0.7.0)
|
||||
json (1.8.2)
|
||||
minitest (5.5.1)
|
||||
rack (1.6.0)
|
||||
minitest (5.6.1)
|
||||
rack (1.6.1)
|
||||
rack-protection (1.5.3)
|
||||
rack
|
||||
rack-test (0.6.3)
|
||||
@@ -57,13 +51,13 @@ GEM
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.2.0)
|
||||
rspec-support (3.2.2)
|
||||
sinatra (1.4.5)
|
||||
sinatra (1.4.6)
|
||||
rack (~> 1.4)
|
||||
rack-protection (~> 1.4)
|
||||
tilt (~> 1.3, >= 1.3.4)
|
||||
tilt (>= 1.3, < 3)
|
||||
sqlite3 (1.3.10)
|
||||
thread_safe (0.3.5)
|
||||
tilt (1.4.1)
|
||||
tilt (2.0.1)
|
||||
timecop (0.7.3)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
|
||||
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
|
||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ['lib']
|
||||
|
||||
spec.add_runtime_dependency 'activejob', '~> 4.0'
|
||||
spec.add_runtime_dependency 'activesupport', '~> 4.0'
|
||||
spec.add_runtime_dependency 'activerecord', '~> 4.0'
|
||||
spec.add_development_dependency 'rake', '~> 10.0'
|
||||
|
||||
@@ -49,7 +49,10 @@ module Crono
|
||||
end
|
||||
|
||||
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
|
||||
when String
|
||||
time = Time.parse(at)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Crono
|
||||
VERSION = '0.8.9'
|
||||
VERSION = '0.9.0'
|
||||
end
|
||||
|
||||
@@ -52,7 +52,7 @@ describe Crono::Period do
|
||||
expect(@period.next(since: 2.days.ago).to_s).to be_eql(Time.now.to_s)
|
||||
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)
|
||||
expect(@period.next.to_s).to be_eql(2.days.from_now.to_s)
|
||||
end
|
||||
@@ -80,7 +80,7 @@ describe Crono::Period do
|
||||
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'")
|
||||
}.to raise_error("period should be at least 1 day to use 'at' with specified hour")
|
||||
end
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user