scheduling 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +3 -0
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.rdoc +4 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +27 -0
- data/Rakefile +39 -0
- data/lib/scheduling.rb +9 -0
- data/lib/scheduling/intersection.rb +66 -0
- data/lib/scheduling/regularity/monthly.rb +37 -0
- data/lib/scheduling/regularity/yearly.rb +29 -0
- data/lib/scheduling/schedule/compound_schedule.rb +7 -0
- data/lib/scheduling/schedule/irregular_schedule.rb +13 -0
- data/lib/scheduling/schedule/regular_schedule.rb +12 -0
- data/lib/scheduling/version.rb +4 -0
- data/scheduling.gemspec +25 -0
- data/spec/intersection_spec.rb +104 -0
- data/spec/regularity/monthly_spec.rb +53 -0
- data/spec/regularity/yearly_spec.rb +59 -0
- data/spec/schedule/compound_schedule_spec.rb +38 -0
- data/spec/schedule/irregular_schedule_spec.rb +26 -0
- data/spec/schedule/regular_schedule_spec.rb +28 -0
- data/spec/scheduling_spec.rb +8 -0
- data/spec/spec_helper.rb +5 -0
- metadata +168 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup rdoc --title "scheduling Documentation" --protected
|
data/ChangeLog.rdoc
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 James Tunnell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= scheduling
|
2
|
+
|
3
|
+
* {Homepage}[https://rubygems.org/gems/scheduling]
|
4
|
+
* {Documentation}[http://rubydoc.info/gems/scheduling/frames]
|
5
|
+
* {Email}[mailto:jamestunnell at gmail.com]
|
6
|
+
|
7
|
+
== Description
|
8
|
+
|
9
|
+
Plan and keep track of project/activity scheduling, including budgeting and accounting.
|
10
|
+
|
11
|
+
== Features
|
12
|
+
|
13
|
+
== Examples
|
14
|
+
|
15
|
+
require 'scheduling'
|
16
|
+
|
17
|
+
== Requirements
|
18
|
+
|
19
|
+
== Install
|
20
|
+
|
21
|
+
$ gem install scheduling
|
22
|
+
|
23
|
+
== Copyright
|
24
|
+
|
25
|
+
Copyright (c) 2013 James Tunnell
|
26
|
+
|
27
|
+
See LICENSE.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler'
|
7
|
+
rescue LoadError => e
|
8
|
+
warn e.message
|
9
|
+
warn "Run `gem install bundler` to install Bundler."
|
10
|
+
exit -1
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
Bundler.setup(:development)
|
15
|
+
rescue Bundler::BundlerError => e
|
16
|
+
warn e.message
|
17
|
+
warn "Run `bundle install` to install missing gems."
|
18
|
+
exit e.status_code
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake'
|
22
|
+
|
23
|
+
require 'rspec/core/rake_task'
|
24
|
+
RSpec::Core::RakeTask.new
|
25
|
+
|
26
|
+
task :test => :spec
|
27
|
+
task :default => :spec
|
28
|
+
|
29
|
+
require "bundler/gem_tasks"
|
30
|
+
|
31
|
+
require 'yard'
|
32
|
+
YARD::Rake::YardocTask.new
|
33
|
+
task :doc => :yard
|
34
|
+
|
35
|
+
require 'rubygems/package_task'
|
36
|
+
Gem::PackageTask.new(Gem::Specification.load('scheduling.gemspec')) do |pkg|
|
37
|
+
pkg.need_tar = true
|
38
|
+
pkg.need_zip = false
|
39
|
+
end
|
data/lib/scheduling.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'scheduling/version'
|
2
|
+
require 'scheduling/intersection'
|
3
|
+
|
4
|
+
require 'scheduling/regularity/monthly'
|
5
|
+
require 'scheduling/regularity/yearly'
|
6
|
+
|
7
|
+
require 'scheduling/schedule/regular_schedule'
|
8
|
+
require 'scheduling/schedule/irregular_schedule'
|
9
|
+
require 'scheduling/schedule/compound_schedule'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class Range
|
2
|
+
class RangeDecreasingError < StandardError; end
|
3
|
+
|
4
|
+
def decreasing?
|
5
|
+
if exclude_end?
|
6
|
+
last < first
|
7
|
+
else
|
8
|
+
last <= first
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def intersect? other
|
13
|
+
raise RangeDecreasingError if other.decreasing?
|
14
|
+
|
15
|
+
if other.first > last
|
16
|
+
return false
|
17
|
+
elsif other.first == last && exclude_end?
|
18
|
+
return false
|
19
|
+
elsif other.last < first
|
20
|
+
return false
|
21
|
+
elsif other.last == first && other.exclude_end?
|
22
|
+
return false
|
23
|
+
else
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def intersection(other)
|
29
|
+
raise RangeDecreasingError if other.decreasing?
|
30
|
+
|
31
|
+
if intersect?(other)
|
32
|
+
if include? other.first
|
33
|
+
start = other.first
|
34
|
+
else # other.first < first
|
35
|
+
start = first
|
36
|
+
end
|
37
|
+
|
38
|
+
if exclude_end?
|
39
|
+
if other.exclude_end?
|
40
|
+
return start...(last < other.last ? last : other.last)
|
41
|
+
else # other is inclusive
|
42
|
+
if other.last <= last
|
43
|
+
return start..other.last
|
44
|
+
else
|
45
|
+
return start...last
|
46
|
+
end
|
47
|
+
end
|
48
|
+
else # self is inclusize
|
49
|
+
if other.exclude_end?
|
50
|
+
if other.last >= last
|
51
|
+
return start..last
|
52
|
+
else other.last < last
|
53
|
+
return start...other.last
|
54
|
+
end
|
55
|
+
else # other is inclusive as well
|
56
|
+
return start..(last < other.last ? last : other.last)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
return nil
|
62
|
+
end
|
63
|
+
|
64
|
+
alias_method :&, :intersection
|
65
|
+
alias_method :intersect, :intersection
|
66
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Scheduling
|
4
|
+
class Monthly
|
5
|
+
def initialize mday
|
6
|
+
@mday = mday
|
7
|
+
if mday > 28
|
8
|
+
@mday = 28
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def occurances date_range
|
13
|
+
raise RangeDecreasingError if date_range.decreasing?
|
14
|
+
|
15
|
+
cur = Date.new(date_range.min.year, date_range.min.month, @mday)
|
16
|
+
|
17
|
+
start = date_range.min
|
18
|
+
if cur < start
|
19
|
+
cur = cur.next_month
|
20
|
+
end
|
21
|
+
|
22
|
+
occurances = []
|
23
|
+
|
24
|
+
stop = date_range.last
|
25
|
+
if date_range.exclude_end?
|
26
|
+
stop -= 1
|
27
|
+
end
|
28
|
+
|
29
|
+
while cur <= stop
|
30
|
+
occurances.push cur
|
31
|
+
cur = cur.next_month
|
32
|
+
end
|
33
|
+
|
34
|
+
return occurances
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Scheduling
|
4
|
+
class Yearly < Struct.new(:month, :mday)
|
5
|
+
def occurances time_range
|
6
|
+
raise RangeDecreasingError if time_range.decreasing?
|
7
|
+
cur = Date.new(time_range.min.year, month, mday)
|
8
|
+
|
9
|
+
start = time_range.min
|
10
|
+
if cur < start
|
11
|
+
cur = cur.next_year
|
12
|
+
end
|
13
|
+
|
14
|
+
occurances = []
|
15
|
+
|
16
|
+
stop = time_range.last
|
17
|
+
if time_range.exclude_end?
|
18
|
+
stop -= 1
|
19
|
+
end
|
20
|
+
|
21
|
+
while cur <= stop
|
22
|
+
occurances.push cur
|
23
|
+
cur = cur.next_year
|
24
|
+
end
|
25
|
+
|
26
|
+
return occurances
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Scheduling
|
2
|
+
class RegularSchedule < Struct.new(:regularity, :date_range)
|
3
|
+
def occurances date_range
|
4
|
+
occurances = []
|
5
|
+
overlap = self.date_range & date_range
|
6
|
+
unless overlap.nil?
|
7
|
+
occurances = regularity.occurances(overlap)
|
8
|
+
end
|
9
|
+
return occurances
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/scheduling.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/scheduling/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "scheduling"
|
7
|
+
gem.version = Scheduling::VERSION
|
8
|
+
gem.summary = %q{Make schedules, regular (yearly, monthly, etc.) or otherwise.}
|
9
|
+
gem.description = %q{Classes for making schedules, that are regular (yearly, monthly, etc.), irregular, or both (compound). Once a schedule is made, and given a target date range, the date of all occurances can be determined. }
|
10
|
+
gem.license = "MIT"
|
11
|
+
gem.authors = ["James Tunnell"]
|
12
|
+
gem.email = "jamestunnell@gmail.com"
|
13
|
+
gem.homepage = "https://rubygems.org/gems/scheduling"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_development_dependency 'bundler', '~> 1.0'
|
21
|
+
gem.add_development_dependency 'rake', '~> 0.8'
|
22
|
+
gem.add_development_dependency 'rspec', '~> 2.4'
|
23
|
+
gem.add_development_dependency 'yard', '~> 0.8'
|
24
|
+
gem.add_development_dependency 'pry'
|
25
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Range#intersection' do
|
4
|
+
it 'should raise error if the other given range is decreasing' do
|
5
|
+
expect { (0..2).intersection(1..0) }.to raise_error
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'range includes end' do
|
9
|
+
context 'second range ends before the first begins' do
|
10
|
+
it 'should return nil' do
|
11
|
+
(5..10).intersection(1..4).should be_nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'second range starts before the first range starts' do
|
16
|
+
context 'second range ends where the first begins' do
|
17
|
+
context 'second range excludes end' do
|
18
|
+
it 'should return nil' do
|
19
|
+
(5..10).intersection(1...5).should be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'second range includes end' do
|
24
|
+
it 'should return a range with the same start/end' do
|
25
|
+
(5..10).intersection(1..5).should eq(5..5)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'second range ends inside first range' do
|
31
|
+
it 'should return a range that starts where the first range starts and ends where the second range ends' do
|
32
|
+
(5..10).intersection(4..6).should eq(5..6)
|
33
|
+
(5..10).intersection(4...6).should eq(5...6)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'second range starts where the first range starts' do
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'second range starts inside the first range' do
|
43
|
+
context 'second range ends inside the first range' do
|
44
|
+
it 'should return the second range' do
|
45
|
+
(5..10).intersection(6..9).should eq(6..9)
|
46
|
+
(5..10).intersection(6...8).should eq(6...8)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'second range ends where the first range ends' do
|
51
|
+
context 'second range is inclusive' do
|
52
|
+
it 'should return the second range' do
|
53
|
+
(5..10).intersection(6..10).should eq(6..10)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'second range is exclusize' do
|
58
|
+
it 'should return an inclusize version of the second range' do
|
59
|
+
(5..10).intersection(6...10).should eq(6..10)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'second range ends after the first range ends' do
|
65
|
+
it 'should return a range starting with the second range and ending with the first' do
|
66
|
+
(5..10).intersection(6..11).should eq(6..10)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'second range starts where the first ends' do
|
72
|
+
it 'should return a range with the same start/end' do
|
73
|
+
(5..10).intersection(10..15).should eq(10..10)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
context 'second range starts after the first ends' do
|
79
|
+
it 'should return nil' do
|
80
|
+
(5..10).intersection(11..15).should be_nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'range excludes end' do
|
86
|
+
before :all do
|
87
|
+
@range = 5...10
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'second range starts where the first ends' do
|
91
|
+
it 'should return nil' do
|
92
|
+
@range.intersection(10..15).should be_nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'second range starts inside the first range' do
|
97
|
+
context 'second range ends outside the first range' do
|
98
|
+
it 'should start where second range starts and end where first range ends (but exclude end)' do
|
99
|
+
@range.intersection(5..15).should eq(5...10)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Monthly do
|
4
|
+
describe '#occurances' do
|
5
|
+
before :all do
|
6
|
+
@cases = [
|
7
|
+
{:mday => 15, :range => Date.new(2003,1,16)..Date.new(2003,2,14), :expected_occurances => 0 },
|
8
|
+
{:mday => 15, :range => Date.new(2003,1,16)...Date.new(2003,2,15), :expected_occurances => 0 },
|
9
|
+
{:mday => 2, :range => Date.new(2020,10,10)..Date.new(2020,10,31), :expected_occurances => 0 },
|
10
|
+
|
11
|
+
{:mday => 15, :range => Date.new(2003,1,15)...Date.new(2003,1,16), :expected_occurances => 1 },
|
12
|
+
{:mday => 15, :range => Date.new(2003,1,14)..Date.new(2003,1,15), :expected_occurances => 1 },
|
13
|
+
{:mday => 10, :range => Date.new(2003,1,14)..Date.new(2003,2,12), :expected_occurances => 1 },
|
14
|
+
{:mday => 22, :range => Date.new(2003,3,20)..Date.new(2003,3,29), :expected_occurances => 1 },
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should produce the expected number of occurances' do
|
19
|
+
@cases.each do |hash|
|
20
|
+
Monthly.new(hash[:mday]).occurances(hash[:range]).count.should eq(hash[:expected_occurances])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should produce occurances all on the given mday' do
|
25
|
+
@cases.each do |hash|
|
26
|
+
Monthly.new(hash[:mday]).occurances(hash[:range]).each do |date|
|
27
|
+
date.mday.should eq(hash[:mday])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should produce occurances all one month apart' do
|
33
|
+
@cases.each do |hash|
|
34
|
+
occurances = Monthly.new(hash[:mday]).occurances(hash[:range])
|
35
|
+
for i in 1...occurances.count
|
36
|
+
if occurances[i] == 1
|
37
|
+
occurances[i-1].month.should eq(12)
|
38
|
+
else
|
39
|
+
(occurances[i].month - occurances[i-1].month).should eq(1)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should produce occurances all within the date range' do
|
46
|
+
@cases.each do |hash|
|
47
|
+
Monthly.new(hash[:mday]).occurances(hash[:range]).each do |date|
|
48
|
+
hash[:range].include? date
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Yearly do
|
4
|
+
describe '#occurances' do
|
5
|
+
context 'time range spans less than 1 year' do
|
6
|
+
context 'original time not in yday range' do
|
7
|
+
it 'should return empty array' do
|
8
|
+
[
|
9
|
+
{:month => 1, :mday => 15, :range => Date.new(2003,1,16)..Date.new(2004,1,14)},
|
10
|
+
{:month => 1, :mday => 15, :range => Date.new(2003,1,14)...Date.new(2003,1,15)},
|
11
|
+
{:month => 2, :mday => 2, :range => Date.new(2020,10,1)...Date.new(2021,2,1)},
|
12
|
+
].each do |hash|
|
13
|
+
Yearly.new(hash[:month], hash[:mday]).occurances(hash[:range]).should be_empty
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'original time is in yday range' do
|
19
|
+
it 'should return array with 1 element' do
|
20
|
+
[
|
21
|
+
{:month => 1, :mday => 15, :range => Date.new(2003,1,15)...Date.new(2003,1,16)},
|
22
|
+
{:month => 1, :mday => 15, :range => Date.new(2003,1,14)..Date.new(2003,1,15)},
|
23
|
+
{:month => 4, :mday => 10, :range => Date.new(2003,1,14)..Date.new(2003,5,15)},
|
24
|
+
{:month => 7, :mday => 22, :range => Date.new(2003,3,1)..Date.new(2004,1,1)},
|
25
|
+
].each do |hash|
|
26
|
+
Yearly.new(hash[:month], hash[:mday]).occurances(hash[:range]).count.should eq(1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'time range spans more than 1 year but less than 2 years' do
|
33
|
+
context 'original time not in yday range' do
|
34
|
+
it 'should return array with 1 element' do
|
35
|
+
[
|
36
|
+
{:month => 1, :mday => 15, :range => Date.new(2003,1,16)..Date.new(2005,1,14)},
|
37
|
+
{:month => 1, :mday => 15, :range => Date.new(2003,1,14)...Date.new(2004,1,15)},
|
38
|
+
{:month => 2, :mday => 2, :range => Date.new(2020,10,1)...Date.new(2022,2,1)},
|
39
|
+
].each do |hash|
|
40
|
+
Yearly.new(hash[:month], hash[:mday]).occurances(hash[:range]).count.should eq(1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'original time is in yday range' do
|
46
|
+
it 'should return array with 2 elements' do
|
47
|
+
[
|
48
|
+
{:month => 1, :mday => 15, :range => Date.new(2003,1,15)...Date.new(2004,1,16)},
|
49
|
+
{:month => 1, :mday => 15, :range => Date.new(2003,1,14)..Date.new(2004,1,15)},
|
50
|
+
{:month => 4, :mday => 10, :range => Date.new(2003,1,14)..Date.new(2004,5,15)},
|
51
|
+
{:month => 7, :mday => 22, :range => Date.new(2003,3,1)..Date.new(2005,1,1)},
|
52
|
+
].each do |hash|
|
53
|
+
Yearly.new(hash[:month], hash[:mday]).occurances(hash[:range]).count.should eq(2)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe CompoundSchedule do
|
4
|
+
describe '#occurances' do
|
5
|
+
context 'date range given does not contain any of the effective dates' do
|
6
|
+
it 'should return []' do
|
7
|
+
sched = CompoundSchedule.new(
|
8
|
+
[IrregularSchedule.new( [ Date.new(2000,2,12), Date.new(2001,1,31) ] ),
|
9
|
+
RegularSchedule.new( Monthly.new(2), Date.new(1998)...Date.new(1999) )]
|
10
|
+
)
|
11
|
+
sched.occurances(Date.new(1999)..Date.new(2000)).should be_empty
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'date range given overlaps with one of the effective dates' do
|
16
|
+
it 'should return one date on the mday' do
|
17
|
+
sched = CompoundSchedule.new(
|
18
|
+
[IrregularSchedule.new( [ Date.new(2000,2,12), Date.new(2001,1,31) ] ),
|
19
|
+
RegularSchedule.new( Monthly.new(2), Date.new(1998)...Date.new(1999) )]
|
20
|
+
)
|
21
|
+
sched.occurances(Date.new(1999)..Date.new(2001)).should eq([Date.new(2000,2,12)])
|
22
|
+
sched.occurances(Date.new(1998)..Date.new(1998,2)).should eq([Date.new(1998,1,2)])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'date range given overlaps with all of the effective dates' do
|
27
|
+
it 'should return all the effective dates' do
|
28
|
+
sched = CompoundSchedule.new(
|
29
|
+
[IrregularSchedule.new( [ Date.new(2000,2,12), Date.new(2001,1,31) ] ),
|
30
|
+
RegularSchedule.new( Monthly.new(2), Date.new(1998,11)..Date.new(1999) )]
|
31
|
+
)
|
32
|
+
sched.occurances(Date.new(1998)..Date.new(2001,2)).should eq(
|
33
|
+
[ Date.new(1998,11,2), Date.new(1998,12,2), Date.new(2000,2,12), Date.new(2001,1,31) ]
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe IrregularSchedule do
|
4
|
+
describe '#occurances' do
|
5
|
+
context 'date range given does not contain any of the effective dates' do
|
6
|
+
it 'should return []' do
|
7
|
+
effect_dates = [ Date.new(2000,2,12), Date.new(2001,1,31) ]
|
8
|
+
IrregularSchedule.new(effect_dates).occurances(Date.new(1999)..Date.new(2000)).should be_empty
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'date range given overlaps with one of the effective dates' do
|
13
|
+
it 'should return one date on the mday' do
|
14
|
+
effect_dates = [ Date.new(2000,2,12), Date.new(2001,1,31) ]
|
15
|
+
IrregularSchedule.new(effect_dates).occurances(Date.new(1999)..Date.new(2001)).should eq( [Date.new(2000,2,12)] )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'date range given overlaps with all of the effective dates' do
|
20
|
+
it 'should return all the effective dates' do
|
21
|
+
effect_dates = [ Date.new(2000,2,12), Date.new(2001,1,31) ]
|
22
|
+
IrregularSchedule.new(effect_dates).occurances(Date.new(1999)..Date.new(2002)).should eq( effect_dates )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RegularSchedule do
|
4
|
+
describe '#occurances' do
|
5
|
+
context 'date range given does not intersect effective date range' do
|
6
|
+
it 'should return []' do
|
7
|
+
RegularSchedule.new(
|
8
|
+
Monthly.new(15),
|
9
|
+
Date.new(2000)...Date.new(2001)
|
10
|
+
).occurances(Date.new(2001)..Date.new(2002)).should be_empty
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'monthly regularity' do
|
15
|
+
context 'date range given overlaps exactly 1 whole month' do
|
16
|
+
it 'should return one date on the mday' do
|
17
|
+
occurances = RegularSchedule.new(
|
18
|
+
Monthly.new(15),
|
19
|
+
Date.new(2000)...Date.new(2001)
|
20
|
+
).occurances(Date.new(2000,12)..Date.new(2001))
|
21
|
+
|
22
|
+
occurances.count.should eq(1)
|
23
|
+
occurances.first.mday.should eq(15)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scheduling
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Tunnell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.8'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.8'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.4'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.4'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: yard
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.8'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.8'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: pry
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: ! 'Classes for making schedules, that are regular (yearly, monthly, etc.),
|
95
|
+
irregular, or both (compound). Once a schedule is made, and given a target date
|
96
|
+
range, the date of all occurances can be determined. '
|
97
|
+
email: jamestunnell@gmail.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .document
|
103
|
+
- .gitignore
|
104
|
+
- .rspec
|
105
|
+
- .yardopts
|
106
|
+
- ChangeLog.rdoc
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.rdoc
|
110
|
+
- Rakefile
|
111
|
+
- lib/scheduling.rb
|
112
|
+
- lib/scheduling/intersection.rb
|
113
|
+
- lib/scheduling/regularity/monthly.rb
|
114
|
+
- lib/scheduling/regularity/yearly.rb
|
115
|
+
- lib/scheduling/schedule/compound_schedule.rb
|
116
|
+
- lib/scheduling/schedule/irregular_schedule.rb
|
117
|
+
- lib/scheduling/schedule/regular_schedule.rb
|
118
|
+
- lib/scheduling/version.rb
|
119
|
+
- scheduling.gemspec
|
120
|
+
- spec/intersection_spec.rb
|
121
|
+
- spec/regularity/monthly_spec.rb
|
122
|
+
- spec/regularity/yearly_spec.rb
|
123
|
+
- spec/schedule/compound_schedule_spec.rb
|
124
|
+
- spec/schedule/irregular_schedule_spec.rb
|
125
|
+
- spec/schedule/regular_schedule_spec.rb
|
126
|
+
- spec/scheduling_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
homepage: https://rubygems.org/gems/scheduling
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
hash: -3343969679380982067
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
hash: -3343969679380982067
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 1.8.23
|
156
|
+
signing_key:
|
157
|
+
specification_version: 3
|
158
|
+
summary: Make schedules, regular (yearly, monthly, etc.) or otherwise.
|
159
|
+
test_files:
|
160
|
+
- spec/intersection_spec.rb
|
161
|
+
- spec/regularity/monthly_spec.rb
|
162
|
+
- spec/regularity/yearly_spec.rb
|
163
|
+
- spec/schedule/compound_schedule_spec.rb
|
164
|
+
- spec/schedule/irregular_schedule_spec.rb
|
165
|
+
- spec/schedule/regular_schedule_spec.rb
|
166
|
+
- spec/scheduling_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
has_rdoc:
|