kalendor 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1a98405233cee526a68ff9a982f998bc3c458ab
4
- data.tar.gz: eea9b41b2f2c1bd20fd5bd9cfd6aba6ae0dcf34c
3
+ metadata.gz: 97a6837962ca266b30b478cf4914dfa97d3767b0
4
+ data.tar.gz: e48e46ba66ae1b2197bbabdf492d6ac2bb0c4551
5
5
  SHA512:
6
- metadata.gz: aff0dcd7b9a2c5757bc8259b30d2be471a5e9329a6163313e905067ea3cbfd1c620623ca259ab35735bd26712fadf79db979178a3fbb144490f35dc8829c1f49
7
- data.tar.gz: bb820ebd991659890c9baada02fff7bf82bec1f7ed8d1fd8a602a99f5046348e75537dcce5bddadd65593c029c4c3d6b432cd401a11582e8c835e7bf089455c0
6
+ metadata.gz: fb03842893c6239cb14fcbcdad293a5aa8017effa0e457b2c2880bc5f14cb27d0654f555f593f5cd5b2517716ea1234739d5a29f53c7cb961d4d393ee4d60b15
7
+ data.tar.gz: e38a91e96fb31279264a1991e915c405d29e51a2a7dc8c4583b3a922e683d4d1941604eb48323fa9bbd6b8bd1bc87f56bf18189056ebb0a0457656aaced5bfb0
data/.gitignore CHANGED
@@ -32,3 +32,4 @@ bm.txt
32
32
  *.o
33
33
  *.a
34
34
  mkmf.log
35
+ spec/examples.txt
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/.*"
@@ -2,7 +2,7 @@ module Kalendor
2
2
  module Interval
3
3
  include Instance
4
4
  def get_dates from, upto
5
- Set.new([from, interval_from].max..[upto, interval_upto].min)
5
+ Set.new([from, interval_from || from].max..[upto, interval_upto || upto].min)
6
6
  end
7
7
  end
8
8
  end
@@ -3,6 +3,6 @@ module Kalendor
3
3
  include Aduki::Initializer
4
4
  attr_accessor :name, :label, :kalendor
5
5
  def get_dates from, upto ; kalendor.get_dates from, upto ; end
6
- def [] m ; return name if m == :name ; end
6
+ def _nydp_get m ; return name if m == :name ; end
7
7
  end
8
8
  end
@@ -1,11 +1,11 @@
1
1
  module Kalendor
2
2
  module Subtract
3
3
  include DateHelper, Instance
4
- def get_dates from, upto ; _included_dates(from, upto) - _excluded_dates(from, upto) ; end
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 _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
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
@@ -1,3 +1,3 @@
1
1
  module Kalendor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,47 +2,62 @@ require 'kalendor'
2
2
  require 'kalendor/instance/interval'
3
3
 
4
4
  RSpec.describe Kalendor::Interval do
5
- let(:interval) {
6
- Kalendor.build { interval "2016-06-01", "2016-06-30" }
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
- it "generates some dates when overlapping before" do
16
- f = date("2000-01-01")
17
- u = date("2016-06-08")
18
- expected = (1..8).map { |d| date("2016-06-0#{d}") }
19
- expect(interval.get_dates(f, u).to_a).to eq expected
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
- it "generates some dates when overlapping inside" do
23
- f = date("2016-06-11")
24
- u = date("2016-06-21")
25
- expected = (11..21).map { |d| date("2016-06-#{d}") }
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
- it "generates all dates when overlapping outside" do
30
- f = date("2016-01-01")
31
- u = date("2016-12-31")
32
- expected = (1..30).map { |d| date("2016-06-#{d}") }
33
- expect(interval.get_dates(f, u).to_a).to eq expected
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
- it "generates some dates when overlapping after" do
37
- f = date("2016-06-21")
38
- u = date("2016-12-31")
39
- expected = (21..30).map { |d| date("2016-06-#{d}") }
40
- expect(interval.get_dates(f, u).to_a).to eq expected
41
- end
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
- it "generates no dates when entirely after" do
44
- f = date("2016-07-01")
45
- u = date("2016-12-31")
46
- expect(interval.get_dates(f, u).to_a).to eq []
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
@@ -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.2
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: 2017-05-07 00:00:00.000000000 Z
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.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 |