kalendor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/kalendor.gemspec +25 -0
- data/lib/kalendor.rb +9 -0
- data/lib/kalendor/annual.rb +15 -0
- data/lib/kalendor/date_helper.rb +85 -0
- data/lib/kalendor/date_list.rb +9 -0
- data/lib/kalendor/factory.rb +57 -0
- data/lib/kalendor/instance.rb +4 -0
- data/lib/kalendor/instance/annual.rb +10 -0
- data/lib/kalendor/instance/composite.rb +7 -0
- data/lib/kalendor/instance/date_list.rb +11 -0
- data/lib/kalendor/instance/intersect.rb +6 -0
- data/lib/kalendor/instance/interval.rb +10 -0
- data/lib/kalendor/instance/month.rb +10 -0
- data/lib/kalendor/instance/store.rb +12 -0
- data/lib/kalendor/instance/subtract.rb +10 -0
- data/lib/kalendor/instance/union.rb +6 -0
- data/lib/kalendor/instance/weekday.rb +9 -0
- data/lib/kalendor/intersect.rb +6 -0
- data/lib/kalendor/interval.rb +8 -0
- data/lib/kalendor/month.rb +18 -0
- data/lib/kalendor/named.rb +7 -0
- data/lib/kalendor/subtract.rb +11 -0
- data/lib/kalendor/union.rb +6 -0
- data/lib/kalendor/version.rb +3 -0
- data/lib/kalendor/weekday.rb +21 -0
- data/spec/annual_spec.rb +35 -0
- data/spec/date_list_spec.rb +22 -0
- data/spec/date_spec.rb +245 -0
- data/spec/examples.txt +34 -0
- data/spec/intersect_spec.rb +20 -0
- data/spec/interval_spec.rb +48 -0
- data/spec/month_spec.rb +57 -0
- data/spec/spec_helper.rb +87 -0
- data/spec/subtract_spec.rb +26 -0
- data/spec/union_spec.rb +27 -0
- data/spec/weekday_spec.rb +27 -0
- data/todo.txt +98 -0
- metadata +168 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
module Kalendor
|
2
|
+
module Month
|
3
|
+
include DateHelper, Instance
|
4
|
+
def get_dates from, upto
|
5
|
+
first = Date.new(from.year, month, 1)
|
6
|
+
last = end_of_month first
|
7
|
+
first = from if first < from && from < last
|
8
|
+
first = Date.new(from.year + 1, month, 1) if last < from
|
9
|
+
result = []
|
10
|
+
while first && (first <= upto)
|
11
|
+
result << first
|
12
|
+
first += 1
|
13
|
+
first = Date.new(first.year + 1, month, 1) if first.month != month
|
14
|
+
end
|
15
|
+
result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Kalendor
|
2
|
+
module Subtract
|
3
|
+
include DateHelper, Instance
|
4
|
+
def get_dates from, upto ; _included_dates(from, upto) - _excluded_dates(from, upto) ; end
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def _excluded_dates from, upto ; Set.new(exclude_dates.get_dates(from, upto)) ; end
|
9
|
+
def _included_dates from, upto ; Set.new(include_dates.get_dates(from, upto)) ; end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'kalendor'
|
2
|
+
|
3
|
+
module Kalendor
|
4
|
+
module Weekday
|
5
|
+
include DateHelper, Instance
|
6
|
+
|
7
|
+
def get_dates from, upto
|
8
|
+
first = beginning_of_week(from) + weekday - 1
|
9
|
+
first = first + 7 if first < from
|
10
|
+
result = []
|
11
|
+
while first && (first <= upto)
|
12
|
+
while nth_of_month && !nth_day_of_month?(first, nth_of_month)
|
13
|
+
first = first + 7
|
14
|
+
end
|
15
|
+
result << first if first <= upto
|
16
|
+
first = first + 7
|
17
|
+
end
|
18
|
+
result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/annual_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'kalendor'
|
2
|
+
require 'kalendor/annual'
|
3
|
+
require 'kalendor/instance/annual'
|
4
|
+
|
5
|
+
RSpec.describe Kalendor::Annual do
|
6
|
+
it "generates birthdays over a number of years" do
|
7
|
+
a = Kalendor.build { annual 18, 11 }
|
8
|
+
birthdays = a.get_dates(date("1960-01-01"), date("1963-12-31"))
|
9
|
+
expect(birthdays).to eq [date("1960-11-18"), date("1961-11-18"), date("1962-11-18"), date("1963-11-18"), ]
|
10
|
+
end
|
11
|
+
|
12
|
+
it "skips #from year if too late" do
|
13
|
+
a = Kalendor.build { annual 18, 11 }
|
14
|
+
birthdays = a.get_dates(date("1960-12-01"), date("1963-12-31"))
|
15
|
+
expect(birthdays).to eq [date("1961-11-18"), date("1962-11-18"), date("1963-11-18"), ]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "skips #upto year if too early" do
|
19
|
+
a = Kalendor.build { annual 18, 11 }
|
20
|
+
birthdays = a.get_dates(date("1960-12-01"), date("1963-01-01"))
|
21
|
+
expect(birthdays).to eq [date("1961-11-18"), date("1962-11-18"), ]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns nothing if period too small and before date" do
|
25
|
+
a = Kalendor.build { annual 18, 11 }
|
26
|
+
birthdays = a.get_dates(date("1960-10-01"), date("1960-11-01"))
|
27
|
+
expect(birthdays).to eq []
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns nothing if period too small and after date" do
|
31
|
+
a = Kalendor.build { annual 18, 11 }
|
32
|
+
birthdays = a.get_dates(date("1960-12-01"), date("1960-12-31"))
|
33
|
+
expect(birthdays).to eq []
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'kalendor'
|
2
|
+
require 'kalendor/instance/date_list'
|
3
|
+
|
4
|
+
RSpec.describe Kalendor::DateList do
|
5
|
+
it "returns a single date" do
|
6
|
+
a = Kalendor.build { list "1984-09-01" }
|
7
|
+
dates = a.get_dates(date("1900-01-01"), date("2100-12-31"))
|
8
|
+
expect(dates).to eq [date("1984-09-01") ]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns a list of dates" do
|
12
|
+
a = Kalendor.build { list "1984-06-21", "1949-10-03", "1982-06-08" }
|
13
|
+
dates = a.get_dates(date("1900-01-01"), date("2100-12-31"))
|
14
|
+
expect(dates).to eq [date("1984-06-21"), date("1949-10-03"), date("1982-06-08"), ]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns only the dates within the given parameterrs " do
|
18
|
+
a = Kalendor.build { list "1984-06-21", "1999-02-11", "1949-10-03", "1882-06-08", "2012-06-08" }
|
19
|
+
dates = a.get_dates(date("1950-01-01"), date("1999-12-31"))
|
20
|
+
expect(dates).to eq [date("1984-06-21"), date("1999-02-11") ]
|
21
|
+
end
|
22
|
+
end
|
data/spec/date_spec.rb
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
require 'kalendor'
|
2
|
+
|
3
|
+
RSpec.describe Kalendor::DateHelper do
|
4
|
+
describe :nth_day_of_month do
|
5
|
+
include Kalendor::DateHelper
|
6
|
+
|
7
|
+
it "should return the index of this week-day in the month" do
|
8
|
+
expect(nth_day_of_month Date.new(2014, 1, 1)).to eq 1 # this is the first wednesday of the month
|
9
|
+
expect(nth_day_of_month Date.new(2014, 1, 2)).to eq 1
|
10
|
+
expect(nth_day_of_month Date.new(2014, 1, 3)).to eq 1
|
11
|
+
expect(nth_day_of_month Date.new(2014, 1, 4)).to eq 1
|
12
|
+
expect(nth_day_of_month Date.new(2014, 1, 5)).to eq 1
|
13
|
+
expect(nth_day_of_month Date.new(2014, 1, 6)).to eq 1
|
14
|
+
expect(nth_day_of_month Date.new(2014, 1, 7)).to eq 1
|
15
|
+
expect(nth_day_of_month Date.new(2014, 1, 8)).to eq 2 # this is the second wednesday of the month
|
16
|
+
expect(nth_day_of_month Date.new(2014, 1, 9)).to eq 2
|
17
|
+
expect(nth_day_of_month Date.new(2014, 1, 10)).to eq 2
|
18
|
+
expect(nth_day_of_month Date.new(2014, 1, 11)).to eq 2
|
19
|
+
expect(nth_day_of_month Date.new(2014, 1, 12)).to eq 2
|
20
|
+
expect(nth_day_of_month Date.new(2014, 1, 13)).to eq 2
|
21
|
+
expect(nth_day_of_month Date.new(2014, 1, 14)).to eq 2
|
22
|
+
expect(nth_day_of_month Date.new(2014, 1, 15)).to eq 3
|
23
|
+
expect(nth_day_of_month Date.new(2014, 1, 16)).to eq 3
|
24
|
+
expect(nth_day_of_month Date.new(2014, 1, 17)).to eq 3
|
25
|
+
expect(nth_day_of_month Date.new(2014, 1, 18)).to eq 3
|
26
|
+
expect(nth_day_of_month Date.new(2014, 1, 19)).to eq 3
|
27
|
+
expect(nth_day_of_month Date.new(2014, 1, 20)).to eq 3
|
28
|
+
expect(nth_day_of_month Date.new(2014, 1, 21)).to eq 3
|
29
|
+
expect(nth_day_of_month Date.new(2014, 1, 22)).to eq 4
|
30
|
+
expect(nth_day_of_month Date.new(2014, 1, 23)).to eq 4
|
31
|
+
expect(nth_day_of_month Date.new(2014, 1, 24)).to eq 4
|
32
|
+
expect(nth_day_of_month Date.new(2014, 1, 25)).to eq 4
|
33
|
+
expect(nth_day_of_month Date.new(2014, 1, 26)).to eq 4
|
34
|
+
expect(nth_day_of_month Date.new(2014, 1, 27)).to eq 4
|
35
|
+
expect(nth_day_of_month Date.new(2014, 1, 28)).to eq 4
|
36
|
+
expect(nth_day_of_month Date.new(2014, 1, 29)).to eq 5 # this is the 5th wednesday of the month
|
37
|
+
expect(nth_day_of_month Date.new(2014, 1, 30)).to eq 5
|
38
|
+
expect(nth_day_of_month Date.new(2014, 1, 31)).to eq 5
|
39
|
+
|
40
|
+
expect(nth_day_of_month Date.new(2014, 2, 1)).to eq 1 # this is the first saturday of the month
|
41
|
+
expect(nth_day_of_month Date.new(2014, 2, 2)).to eq 1
|
42
|
+
expect(nth_day_of_month Date.new(2014, 2, 3)).to eq 1
|
43
|
+
expect(nth_day_of_month Date.new(2014, 2, 4)).to eq 1
|
44
|
+
expect(nth_day_of_month Date.new(2014, 2, 5)).to eq 1
|
45
|
+
expect(nth_day_of_month Date.new(2014, 2, 6)).to eq 1
|
46
|
+
expect(nth_day_of_month Date.new(2014, 2, 7)).to eq 1
|
47
|
+
expect(nth_day_of_month Date.new(2014, 2, 8)).to eq 2 # this is the second saturday of the month
|
48
|
+
expect(nth_day_of_month Date.new(2014, 2, 9)).to eq 2
|
49
|
+
expect(nth_day_of_month Date.new(2014, 2, 10)).to eq 2
|
50
|
+
expect(nth_day_of_month Date.new(2014, 2, 11)).to eq 2
|
51
|
+
expect(nth_day_of_month Date.new(2014, 2, 12)).to eq 2
|
52
|
+
expect(nth_day_of_month Date.new(2014, 2, 13)).to eq 2
|
53
|
+
expect(nth_day_of_month Date.new(2014, 2, 14)).to eq 2
|
54
|
+
expect(nth_day_of_month Date.new(2014, 2, 15)).to eq 3
|
55
|
+
expect(nth_day_of_month Date.new(2014, 2, 16)).to eq 3
|
56
|
+
expect(nth_day_of_month Date.new(2014, 2, 17)).to eq 3
|
57
|
+
expect(nth_day_of_month Date.new(2014, 2, 18)).to eq 3
|
58
|
+
expect(nth_day_of_month Date.new(2014, 2, 19)).to eq 3
|
59
|
+
expect(nth_day_of_month Date.new(2014, 2, 20)).to eq 3
|
60
|
+
expect(nth_day_of_month Date.new(2014, 2, 21)).to eq 3
|
61
|
+
expect(nth_day_of_month Date.new(2014, 2, 22)).to eq 4
|
62
|
+
expect(nth_day_of_month Date.new(2014, 2, 23)).to eq 4
|
63
|
+
expect(nth_day_of_month Date.new(2014, 2, 24)).to eq 4
|
64
|
+
expect(nth_day_of_month Date.new(2014, 2, 25)).to eq 4
|
65
|
+
expect(nth_day_of_month Date.new(2014, 2, 26)).to eq 4
|
66
|
+
expect(nth_day_of_month Date.new(2014, 2, 27)).to eq 4
|
67
|
+
expect(nth_day_of_month Date.new(2014, 2, 28)).to eq 4 # this is the fourth friday of the month
|
68
|
+
|
69
|
+
expect(nth_day_of_month Date.new(2014, 3, 1)).to eq 1
|
70
|
+
expect(nth_day_of_month Date.new(2014, 3, 2)).to eq 1
|
71
|
+
expect(nth_day_of_month Date.new(2014, 3, 3)).to eq 1
|
72
|
+
expect(nth_day_of_month Date.new(2014, 3, 4)).to eq 1
|
73
|
+
expect(nth_day_of_month Date.new(2014, 3, 5)).to eq 1
|
74
|
+
expect(nth_day_of_month Date.new(2014, 3, 6)).to eq 1
|
75
|
+
expect(nth_day_of_month Date.new(2014, 3, 7)).to eq 1
|
76
|
+
expect(nth_day_of_month Date.new(2014, 3, 8)).to eq 2
|
77
|
+
expect(nth_day_of_month Date.new(2014, 3, 9)).to eq 2
|
78
|
+
expect(nth_day_of_month Date.new(2014, 3, 10)).to eq 2
|
79
|
+
expect(nth_day_of_month Date.new(2014, 3, 11)).to eq 2
|
80
|
+
expect(nth_day_of_month Date.new(2014, 3, 12)).to eq 2
|
81
|
+
expect(nth_day_of_month Date.new(2014, 3, 13)).to eq 2
|
82
|
+
expect(nth_day_of_month Date.new(2014, 3, 14)).to eq 2
|
83
|
+
expect(nth_day_of_month Date.new(2014, 3, 15)).to eq 3
|
84
|
+
expect(nth_day_of_month Date.new(2014, 3, 16)).to eq 3
|
85
|
+
expect(nth_day_of_month Date.new(2014, 3, 17)).to eq 3
|
86
|
+
expect(nth_day_of_month Date.new(2014, 3, 18)).to eq 3
|
87
|
+
expect(nth_day_of_month Date.new(2014, 3, 19)).to eq 3
|
88
|
+
expect(nth_day_of_month Date.new(2014, 3, 20)).to eq 3
|
89
|
+
expect(nth_day_of_month Date.new(2014, 3, 21)).to eq 3
|
90
|
+
expect(nth_day_of_month Date.new(2014, 3, 22)).to eq 4
|
91
|
+
expect(nth_day_of_month Date.new(2014, 3, 23)).to eq 4
|
92
|
+
expect(nth_day_of_month Date.new(2014, 3, 24)).to eq 4
|
93
|
+
expect(nth_day_of_month Date.new(2014, 3, 25)).to eq 4
|
94
|
+
expect(nth_day_of_month Date.new(2014, 3, 26)).to eq 4
|
95
|
+
expect(nth_day_of_month Date.new(2014, 3, 27)).to eq 4
|
96
|
+
expect(nth_day_of_month Date.new(2014, 3, 28)).to eq 4
|
97
|
+
expect(nth_day_of_month Date.new(2014, 3, 29)).to eq 5
|
98
|
+
expect(nth_day_of_month Date.new(2014, 3, 30)).to eq 5
|
99
|
+
expect(nth_day_of_month Date.new(2014, 3, 31)).to eq 5
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe :nth_last_day_of_month do
|
104
|
+
include Kalendor::DateHelper
|
105
|
+
|
106
|
+
it "should return the index of this week-day in the month" do
|
107
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 1)).to eq(-5) # this is the fifth last wednesday of the month
|
108
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 2)).to eq(-5)
|
109
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 3)).to eq(-5)
|
110
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 4)).to eq(-4)
|
111
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 5)).to eq(-4)
|
112
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 6)).to eq(-4)
|
113
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 7)).to eq(-4)
|
114
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 8)).to eq(-4) # this is the fourth last wednesday of the month
|
115
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 9)).to eq(-4)
|
116
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 10)).to eq(-4)
|
117
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 11)).to eq(-3)
|
118
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 12)).to eq(-3)
|
119
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 13)).to eq(-3)
|
120
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 14)).to eq(-3)
|
121
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 15)).to eq(-3)
|
122
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 16)).to eq(-3)
|
123
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 17)).to eq(-3)
|
124
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 18)).to eq(-2)
|
125
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 19)).to eq(-2)
|
126
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 20)).to eq(-2)
|
127
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 21)).to eq(-2)
|
128
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 22)).to eq(-2)
|
129
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 23)).to eq(-2)
|
130
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 24)).to eq(-2)
|
131
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 25)).to eq(-1)
|
132
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 26)).to eq(-1)
|
133
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 27)).to eq(-1)
|
134
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 28)).to eq(-1)
|
135
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 29)).to eq(-1) # this is the last wednesday of the month
|
136
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 30)).to eq(-1)
|
137
|
+
expect(nth_last_day_of_month Date.new(2014, 1, 31)).to eq(-1)
|
138
|
+
|
139
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 1)).to eq(-4) # this is the fourth last saturday of the month
|
140
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 2)).to eq(-4)
|
141
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 3)).to eq(-4)
|
142
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 4)).to eq(-4)
|
143
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 5)).to eq(-4)
|
144
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 6)).to eq(-4)
|
145
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 7)).to eq(-4)
|
146
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 8)).to eq(-3) # this is the third last saturday of the month
|
147
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 9)).to eq(-3)
|
148
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 10)).to eq(-3)
|
149
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 11)).to eq(-3)
|
150
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 12)).to eq(-3)
|
151
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 13)).to eq(-3)
|
152
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 14)).to eq(-3)
|
153
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 15)).to eq(-2)
|
154
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 16)).to eq(-2)
|
155
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 17)).to eq(-2)
|
156
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 18)).to eq(-2)
|
157
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 19)).to eq(-2)
|
158
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 20)).to eq(-2)
|
159
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 21)).to eq(-2)
|
160
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 22)).to eq(-1)
|
161
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 23)).to eq(-1)
|
162
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 24)).to eq(-1)
|
163
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 25)).to eq(-1)
|
164
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 26)).to eq(-1)
|
165
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 27)).to eq(-1)
|
166
|
+
expect(nth_last_day_of_month Date.new(2014, 2, 28)).to eq(-1) # this is the last friday of the month
|
167
|
+
|
168
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 1)).to eq(-5)
|
169
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 2)).to eq(-5)
|
170
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 3)).to eq(-5)
|
171
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 4)).to eq(-4)
|
172
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 5)).to eq(-4)
|
173
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 6)).to eq(-4)
|
174
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 7)).to eq(-4)
|
175
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 8)).to eq(-4)
|
176
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 9)).to eq(-4)
|
177
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 10)).to eq(-4)
|
178
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 11)).to eq(-3)
|
179
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 12)).to eq(-3)
|
180
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 13)).to eq(-3)
|
181
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 14)).to eq(-3)
|
182
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 15)).to eq(-3)
|
183
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 16)).to eq(-3)
|
184
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 17)).to eq(-3)
|
185
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 18)).to eq(-2)
|
186
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 19)).to eq(-2)
|
187
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 20)).to eq(-2)
|
188
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 21)).to eq(-2)
|
189
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 22)).to eq(-2)
|
190
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 23)).to eq(-2)
|
191
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 24)).to eq(-2)
|
192
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 25)).to eq(-1)
|
193
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 26)).to eq(-1)
|
194
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 27)).to eq(-1)
|
195
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 28)).to eq(-1)
|
196
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 29)).to eq(-1)
|
197
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 30)).to eq(-1)
|
198
|
+
expect(nth_last_day_of_month Date.new(2014, 3, 31)).to eq(-1)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe :nth_day_of_month? do
|
203
|
+
include Kalendor::DateHelper
|
204
|
+
|
205
|
+
it "returns true when the date is the given nth weekday of the month" do
|
206
|
+
d = Date.new(2014, 3, 1)
|
207
|
+
expect(nth_day_of_month?(d, 1)).to eq true
|
208
|
+
expect(nth_day_of_month?(d, 2)).to eq false
|
209
|
+
expect(nth_day_of_month?(d, 3)).to eq false
|
210
|
+
expect(nth_day_of_month?(d, 4)).to eq false
|
211
|
+
expect(nth_day_of_month?(d, 5)).to eq false
|
212
|
+
expect(nth_day_of_month?(d, -5)).to eq true
|
213
|
+
expect(nth_day_of_month?(d, -4)).to eq false
|
214
|
+
expect(nth_day_of_month?(d, -3)).to eq false
|
215
|
+
expect(nth_day_of_month?(d, -2)).to eq false
|
216
|
+
expect(nth_day_of_month?(d, -1)).to eq false
|
217
|
+
|
218
|
+
d = Date.new(2014, 3, 15)
|
219
|
+
expect(nth_day_of_month?(d, 1)).to eq false
|
220
|
+
expect(nth_day_of_month?(d, 2)).to eq false
|
221
|
+
expect(nth_day_of_month?(d, 3)).to eq true
|
222
|
+
expect(nth_day_of_month?(d, 4)).to eq false
|
223
|
+
expect(nth_day_of_month?(d, 5)).to eq false
|
224
|
+
expect(nth_day_of_month?(d, -5)).to eq false
|
225
|
+
expect(nth_day_of_month?(d, -4)).to eq false
|
226
|
+
expect(nth_day_of_month?(d, -3)).to eq true
|
227
|
+
expect(nth_day_of_month?(d, -2)).to eq false
|
228
|
+
expect(nth_day_of_month?(d, -1)).to eq false
|
229
|
+
|
230
|
+
d = Date.new(2014, 3, 31)
|
231
|
+
expect(nth_day_of_month?(d, 1)).to eq false
|
232
|
+
expect(nth_day_of_month?(d, 2)).to eq false
|
233
|
+
expect(nth_day_of_month?(d, 3)).to eq false
|
234
|
+
expect(nth_day_of_month?(d, 4)).to eq false
|
235
|
+
expect(nth_day_of_month?(d, 5)).to eq true
|
236
|
+
expect(nth_day_of_month?(d, -5)).to eq false
|
237
|
+
expect(nth_day_of_month?(d, -4)).to eq false
|
238
|
+
expect(nth_day_of_month?(d, -3)).to eq false
|
239
|
+
expect(nth_day_of_month?(d, -2)).to eq false
|
240
|
+
expect(nth_day_of_month?(d, -1)).to eq true
|
241
|
+
|
242
|
+
expect { nth_day_of_month?(d, 0) }.to raise_error(ArgumentError)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
data/spec/examples.txt
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
example_id | status | run_time |
|
2
|
+
----------------------------- | ------ | --------------- |
|
3
|
+
./spec/annual_spec.rb[1:1] | passed | 0.00076 seconds |
|
4
|
+
./spec/annual_spec.rb[1:2] | passed | 0.00013 seconds |
|
5
|
+
./spec/annual_spec.rb[1:3] | passed | 0.00012 seconds |
|
6
|
+
./spec/annual_spec.rb[1:4] | passed | 0.00012 seconds |
|
7
|
+
./spec/annual_spec.rb[1:5] | passed | 0.00012 seconds |
|
8
|
+
./spec/date_list_spec.rb[1:1] | passed | 0.0001 seconds |
|
9
|
+
./spec/date_list_spec.rb[1:2] | passed | 0.00015 seconds |
|
10
|
+
./spec/date_list_spec.rb[1:3] | passed | 0.00017 seconds |
|
11
|
+
./spec/date_spec.rb[1:1:1] | passed | 0.00026 seconds |
|
12
|
+
./spec/date_spec.rb[1:2:1] | passed | 0.00068 seconds |
|
13
|
+
./spec/date_spec.rb[1:3:1] | passed | 0.00089 seconds |
|
14
|
+
./spec/intersect_spec.rb[1:1] | passed | 0.00589 seconds |
|
15
|
+
./spec/interval_spec.rb[1:1] | passed | 0.00048 seconds |
|
16
|
+
./spec/interval_spec.rb[1:2] | passed | 0.0002 seconds |
|
17
|
+
./spec/interval_spec.rb[1:3] | passed | 0.0002 seconds |
|
18
|
+
./spec/interval_spec.rb[1:4] | passed | 0.00031 seconds |
|
19
|
+
./spec/interval_spec.rb[1:5] | passed | 0.00018 seconds |
|
20
|
+
./spec/interval_spec.rb[1:6] | passed | 0.00013 seconds |
|
21
|
+
./spec/month_spec.rb[1:1] | passed | 0.00843 seconds |
|
22
|
+
./spec/month_spec.rb[1:2] | passed | 0.00021 seconds |
|
23
|
+
./spec/month_spec.rb[1:3] | passed | 0.00021 seconds |
|
24
|
+
./spec/month_spec.rb[1:4] | passed | 0.00048 seconds |
|
25
|
+
./spec/month_spec.rb[1:5] | passed | 0.00016 seconds |
|
26
|
+
./spec/month_spec.rb[1:6] | passed | 0.00012 seconds |
|
27
|
+
./spec/month_spec.rb[1:7] | passed | 0.00197 seconds |
|
28
|
+
./spec/subtract_spec.rb[1:1] | passed | 0.01205 seconds |
|
29
|
+
./spec/union_spec.rb[1:1] | passed | 0.00034 seconds |
|
30
|
+
./spec/union_spec.rb[1:2] | passed | 0.00032 seconds |
|
31
|
+
./spec/weekday_spec.rb[1:1] | passed | 0.00012 seconds |
|
32
|
+
./spec/weekday_spec.rb[1:2] | passed | 0.00015 seconds |
|
33
|
+
./spec/weekday_spec.rb[1:3] | passed | 0.00021 seconds |
|
34
|
+
./spec/weekday_spec.rb[1:4] | passed | 0.00025 seconds |
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'kalendor'
|
2
|
+
require 'kalendor/instance/intersect'
|
3
|
+
require 'kalendor/instance/interval'
|
4
|
+
require 'kalendor/instance/union'
|
5
|
+
require 'kalendor/instance/weekday'
|
6
|
+
|
7
|
+
RSpec.describe Kalendor::Intersect do
|
8
|
+
it "produces every weekend in summer 2016" do
|
9
|
+
summer_weekends = Kalendor.build do
|
10
|
+
intersect(union(weekday(6), weekday(7)), interval(date("2016-06-01"), date("2016-08-31")))
|
11
|
+
end
|
12
|
+
|
13
|
+
weekends_in_jun_2016 = [4,5,11,12,18,19,25,26 ].map { |d| date("2016-06-#{d}") }
|
14
|
+
weekends_in_jul_2016 = [2,3,9,10,16,17,23,24,30,31].map { |d| date("2016-07-#{d}") }
|
15
|
+
weekends_in_aug_2016 = [6,7,13,14,20,21,27,28 ].map { |d| date("2016-08-#{d}") }
|
16
|
+
weekends_in_summer_2016 = weekends_in_jun_2016 + weekends_in_jul_2016 + weekends_in_aug_2016
|
17
|
+
|
18
|
+
expect(summer_weekends.get_dates(date("1999-01-01"), date("2020-12-31")).to_a).to eq weekends_in_summer_2016
|
19
|
+
end
|
20
|
+
end
|