kalendor 0.0.2 → 0.0.3
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 +4 -4
- data/.gitignore +1 -0
- data/.zeiger.yml +28 -0
- data/lib/kalendor/interval.rb +1 -1
- data/lib/kalendor/named.rb +1 -1
- data/lib/kalendor/subtract.rb +3 -3
- data/lib/kalendor/version.rb +1 -1
- data/spec/interval_spec.rb +51 -36
- data/spec/subtract_spec.rb +22 -0
- metadata +4 -5
- data/spec/examples.txt +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97a6837962ca266b30b478cf4914dfa97d3767b0
|
4
|
+
data.tar.gz: e48e46ba66ae1b2197bbabdf492d6ac2bb0c4551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb03842893c6239cb14fcbcdad293a5aa8017effa0e457b2c2880bc5f14cb27d0654f555f593f5cd5b2517716ea1234739d5a29f53c7cb961d4d393ee4d60b15
|
7
|
+
data.tar.gz: e38a91e96fb31279264a1991e915c405d29e51a2a7dc8c4583b3a922e683d4d1941604eb48323fa9bbd6b8bd1bc87f56bf18189056ebb0a0457656aaced5bfb0
|
data/.gitignore
CHANGED
data/.zeiger.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
search:
|
2
|
+
- "bin/**/*"
|
3
|
+
- "lib/**/*"
|
4
|
+
- "spec/**/*"
|
5
|
+
- "*.gemspec"
|
6
|
+
- ".*.yml"
|
7
|
+
- ".git?*"
|
8
|
+
- "Gemfile*"
|
9
|
+
- README
|
10
|
+
ignore:
|
11
|
+
- .doc$
|
12
|
+
- .ods$
|
13
|
+
- .gz$
|
14
|
+
- .png$
|
15
|
+
- .gif$
|
16
|
+
- .zip$
|
17
|
+
- .jpg$
|
18
|
+
- .xcf$
|
19
|
+
- .pdf$
|
20
|
+
- /select2/.*.js$
|
21
|
+
stats:
|
22
|
+
nydp:
|
23
|
+
- ".*\\.nydp"
|
24
|
+
code:
|
25
|
+
- "lib/.*\\.(rb|rake)"
|
26
|
+
test:
|
27
|
+
- "spec/.*"
|
28
|
+
- "test/.*"
|
data/lib/kalendor/interval.rb
CHANGED
data/lib/kalendor/named.rb
CHANGED
data/lib/kalendor/subtract.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Kalendor
|
2
2
|
module Subtract
|
3
3
|
include DateHelper, Instance
|
4
|
-
def get_dates from, upto ;
|
4
|
+
def get_dates from, upto ; in_dates(include_dates, from, upto) - ex_dates(exclude_dates, from, upto) ; end
|
5
5
|
|
6
6
|
private
|
7
7
|
|
8
|
-
def
|
9
|
-
def
|
8
|
+
def in_dates cal, from, upto ; Set.new(cal ? cal.get_dates(from, upto) : (from..upto)) ; end
|
9
|
+
def ex_dates cal, from, upto ; Set.new(cal ? cal.get_dates(from, upto) : []) ; end
|
10
10
|
end
|
11
11
|
end
|
data/lib/kalendor/version.rb
CHANGED
data/spec/interval_spec.rb
CHANGED
@@ -2,47 +2,62 @@ require 'kalendor'
|
|
2
2
|
require 'kalendor/instance/interval'
|
3
3
|
|
4
4
|
RSpec.describe Kalendor::Interval do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
it "generates nothing when entirely before" do
|
10
|
-
f = date("2000-01-01")
|
11
|
-
u = date("2000-12-31")
|
12
|
-
expect(interval.get_dates(f, u).to_a).to eq []
|
13
|
-
end
|
5
|
+
describe "with nil start and finish dates" do
|
6
|
+
let(:interval) {
|
7
|
+
Kalendor.build { interval nil, nil }
|
8
|
+
}
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
it "generates all of the given dates" do
|
11
|
+
f = date("2000-12-01")
|
12
|
+
u = date("2000-12-31")
|
13
|
+
expected = (1..31).map { |d| date("2000-12-#{d}") }
|
14
|
+
expect(interval.get_dates(f, u).to_a).to eq expected
|
15
|
+
end
|
20
16
|
end
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
expect(interval.get_dates(f, u).to_a).to eq expected
|
27
|
-
end
|
18
|
+
describe "with a start and a finish date" do
|
19
|
+
let(:interval) {
|
20
|
+
Kalendor.build { interval "2016-06-01", "2016-06-30" }
|
21
|
+
}
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
23
|
+
it "generates nothing when entirely before" do
|
24
|
+
f = date("2000-01-01")
|
25
|
+
u = date("2000-12-31")
|
26
|
+
expect(interval.get_dates(f, u).to_a).to eq []
|
27
|
+
end
|
35
28
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
29
|
+
it "generates some dates when overlapping before" do
|
30
|
+
f = date("2000-01-01")
|
31
|
+
u = date("2016-06-08")
|
32
|
+
expected = (1..8).map { |d| date("2016-06-0#{d}") }
|
33
|
+
expect(interval.get_dates(f, u).to_a).to eq expected
|
34
|
+
end
|
35
|
+
|
36
|
+
it "generates some dates when overlapping inside" do
|
37
|
+
f = date("2016-06-11")
|
38
|
+
u = date("2016-06-21")
|
39
|
+
expected = (11..21).map { |d| date("2016-06-#{d}") }
|
40
|
+
expect(interval.get_dates(f, u).to_a).to eq expected
|
41
|
+
end
|
42
|
+
|
43
|
+
it "generates all dates when overlapping outside" do
|
44
|
+
f = date("2016-01-01")
|
45
|
+
u = date("2016-12-31")
|
46
|
+
expected = (1..30).map { |d| date("2016-06-#{d}") }
|
47
|
+
expect(interval.get_dates(f, u).to_a).to eq expected
|
48
|
+
end
|
49
|
+
|
50
|
+
it "generates some dates when overlapping after" do
|
51
|
+
f = date("2016-06-21")
|
52
|
+
u = date("2016-12-31")
|
53
|
+
expected = (21..30).map { |d| date("2016-06-#{d}") }
|
54
|
+
expect(interval.get_dates(f, u).to_a).to eq expected
|
55
|
+
end
|
42
56
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
57
|
+
it "generates no dates when entirely after" do
|
58
|
+
f = date("2016-07-01")
|
59
|
+
u = date("2016-12-31")
|
60
|
+
expect(interval.get_dates(f, u).to_a).to eq []
|
61
|
+
end
|
47
62
|
end
|
48
63
|
end
|
data/spec/subtract_spec.rb
CHANGED
@@ -23,4 +23,26 @@ RSpec.describe Kalendor::Subtract do
|
|
23
23
|
|
24
24
|
expect(summer_workdays.get_dates(date("1999-01-01"), date("2020-12-31")).to_a).to eq workdays_in_summer_2016
|
25
25
|
end
|
26
|
+
|
27
|
+
it "ignores nil exclude_dates" do
|
28
|
+
all_summer_long = Kalendor.build { subtract(interval("2016-06-01", "2016-08-31"), nil) }
|
29
|
+
|
30
|
+
days_in_jun_2016 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 ].map { |d| date("2016-06-#{d}") }
|
31
|
+
days_in_jul_2016 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31].map { |d| date("2016-07-#{d}") }
|
32
|
+
days_in_aug_2016 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31].map { |d| date("2016-08-#{d}") }
|
33
|
+
days_in_summer_2016 = days_in_jun_2016 + days_in_jul_2016 + days_in_aug_2016
|
34
|
+
|
35
|
+
expect(all_summer_long.get_dates(date("1999-01-01"), date("2020-12-31")).to_a).to eq days_in_summer_2016
|
36
|
+
end
|
37
|
+
|
38
|
+
it "ignores nil include_dates" do
|
39
|
+
no_weekends = Kalendor.build { subtract(nil, union(weekday(6), weekday(0))) }
|
40
|
+
|
41
|
+
weekdays_in_jun_2016 = [1,2,3, 6,7,8,9,10, 13,14,15,16,17, 20,21,22,23,24, 27,28,29,30 ].map { |d| date("2016-06-#{d}") }
|
42
|
+
weekdays_in_jul_2016 = [1, 4,5,6,7,8, 11,12,13,14,15, 18,19,20,21,22, 25,26,27,28,29 ].map { |d| date("2016-07-#{d}") }
|
43
|
+
weekdays_in_aug_2016 = [1,2,3,4,5, 8,9,10,11,12, 15,16,17,18,19, 22,23,24,25,26, 29,30,31].map { |d| date("2016-08-#{d}") }
|
44
|
+
weekdays_in_summer_2016 = weekdays_in_jun_2016 + weekdays_in_jul_2016 + weekdays_in_aug_2016
|
45
|
+
|
46
|
+
expect(no_weekends.get_dates(date("2016-06-01"), date("2016-08-31")).to_a).to eq weekdays_in_summer_2016
|
47
|
+
end
|
26
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kalendor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conan Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aduki
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
+
- ".zeiger.yml"
|
92
93
|
- Gemfile
|
93
94
|
- MIT-LICENSE.txt
|
94
95
|
- README.md
|
@@ -121,7 +122,6 @@ files:
|
|
121
122
|
- spec/annual_spec.rb
|
122
123
|
- spec/date_list_spec.rb
|
123
124
|
- spec/date_spec.rb
|
124
|
-
- spec/examples.txt
|
125
125
|
- spec/intersect_spec.rb
|
126
126
|
- spec/interval_spec.rb
|
127
127
|
- spec/month_spec.rb
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.2.
|
153
|
+
rubygems_version: 2.5.2.3
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Utility classes for generating sets of dates
|
@@ -158,7 +158,6 @@ test_files:
|
|
158
158
|
- spec/annual_spec.rb
|
159
159
|
- spec/date_list_spec.rb
|
160
160
|
- spec/date_spec.rb
|
161
|
-
- spec/examples.txt
|
162
161
|
- spec/intersect_spec.rb
|
163
162
|
- spec/interval_spec.rb
|
164
163
|
- spec/month_spec.rb
|
data/spec/examples.txt
DELETED
@@ -1,34 +0,0 @@
|
|
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 |
|