edtf 3.2.0 → 3.3.0

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.
data/lib/edtf/parser.y CHANGED
@@ -135,13 +135,45 @@ rule
135
135
  result = Date.new(val[0]).unspecified!([:day,:month])
136
136
  }
137
137
 
138
- level_1_interval : level_1_start '/' level_1_end {
138
+ level_1_interval : level_1_interval_closed | level_1_interval_open | level_1_interval_unknown
139
+
140
+ level_1_interval_closed : level_1_start '/' level_1_end {
139
141
  result = Interval.new(val[0], val[2])
140
142
  }
141
143
 
142
- level_1_start : date | partial_uncertain_or_approximate | unspecified | partial_unspecified | UNKNOWN
144
+ level_1_interval_open : level_1_interval_open_start | level_1_interval_open_end
145
+
146
+ level_1_interval_open_start : open_start_or_end '/' level_1_end {
147
+ result = Interval.new(:open, val[2])
148
+ }
149
+
150
+ level_1_interval_open_end : level_1_start '/' open_start_or_end {
151
+ result = Interval.new(val[0], :open)
152
+ }
153
+
154
+ open_start_or_end : OPEN | DOTS
155
+
156
+ level_1_interval_unknown : level_1_interval_empty_start | level_1_interval_empty_end | level_1_interval_unknown_start | level_1_interval_unknown_end
157
+
158
+ level_1_interval_empty_start : '/' level_1_end {
159
+ result = Interval.new(:unknown, val[1])
160
+ }
161
+
162
+ level_1_interval_empty_end : level_1_start '/' {
163
+ result = Interval.new(val[0], :unknown)
164
+ }
165
+
166
+ level_1_interval_unknown_start : UNKNOWN '/' level_1_end {
167
+ result = Interval.new(:unknown, val[2])
168
+ }
169
+
170
+ level_1_interval_unknown_end : level_1_start '/' UNKNOWN {
171
+ result = Interval.new(val[0], :unknown)
172
+ }
173
+
174
+ level_1_start : date | partial_uncertain_or_approximate | unspecified | partial_unspecified
143
175
 
144
- level_1_end : level_1_start | OPEN
176
+ level_1_end : level_1_start
145
177
 
146
178
 
147
179
  long_year_simple :
@@ -260,8 +292,8 @@ rule
260
292
  | year DOTS { result = Date.new(val[0]).year_precision! }
261
293
  ;
262
294
 
263
- consecutives : year_month_day DOTS year_month_day { result = (Date.new(val[0]).day_precision! .. Date.new(val[2]).day_precision!) }
264
- | year_month DOTS year_month { result = (Date.new(val[0]).month_precision! .. Date.new(val[2]).month_precision!) }
295
+ consecutives : year_month_day DOTS year_month_day { result = (Date.new(*val[0]).day_precision! .. Date.new(*val[2]).day_precision!) }
296
+ | year_month DOTS year_month { result = (Date.new(*val[0]).month_precision! .. Date.new(*val[2]).month_precision!) }
265
297
  | year DOTS year { result = (Date.new(val[0]).year_precision! .. Date.new(val[2]).year_precision!) }
266
298
  ;
267
299
 
data/lib/edtf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module EDTF
2
- VERSION = '3.2.0'.freeze
2
+ VERSION = '3.3.0'.freeze
3
3
  end
@@ -106,6 +106,99 @@ module EDTF
106
106
 
107
107
  end
108
108
 
109
+ describe 'the interval 2008-08-23/..' do
110
+ let(:interval) { Date.edtf('2008-08-23/..') }
111
+
112
+ it { expect(interval).to be_open }
113
+ it { expect(interval).to be_open_end }
114
+ it { expect(interval).not_to be_unknown }
115
+ it { expect(interval).not_to be_unknown_start }
116
+ it { expect(interval).not_to be_unknown_end }
117
+
118
+ it 'the min date is 2008-08-23' do
119
+ expect(interval.min).to eq(Date.new(2008,8,23))
120
+ end
121
+
122
+ it 'the max date is nil' do
123
+ expect(interval.max).to be nil
124
+ end
125
+
126
+ it 'includes christmas day 2009' do
127
+ expect(interval).to be_include(Date.new(2009,12,24))
128
+ end
129
+
130
+ it 'covers christmas day 2009' do
131
+ expect(interval).to be_cover(Date.new(2009,12,24))
132
+ end
133
+
134
+ it 'covers 2023-07-02' do
135
+ expect(interval).to be_cover(Date.new(2023,07,02))
136
+ end
137
+
138
+ end
139
+
140
+ describe 'the interval open/2008-08-23' do
141
+ let(:interval) { Date.edtf('open/2008-08-23') }
142
+
143
+ it { expect(interval).to be_open }
144
+ it { expect(interval).to be_open_start }
145
+ it { expect(interval).not_to be_open_end }
146
+ it { expect(interval).not_to be_unknown }
147
+ it { expect(interval).not_to be_unknown_start }
148
+ it { expect(interval).not_to be_unknown_end }
149
+
150
+ it 'the max date is 2008-08-23' do
151
+ expect(interval.max).to eq(Date.new(2008,8,23))
152
+ end
153
+
154
+ it 'the min date is nil' do
155
+ expect(interval.min).to be nil
156
+ end
157
+
158
+ it 'includes christmas day 2007' do
159
+ expect(interval).to be_include(Date.new(2007,12,24))
160
+ end
161
+
162
+ it 'covers christmas day 2007' do
163
+ expect(interval).to be_cover(Date.new(2007,12,24))
164
+ end
165
+
166
+ it 'covers 2003-07-02' do
167
+ expect(interval).to be_cover(Date.new(2003,07,02))
168
+ end
169
+ end
170
+
171
+ describe 'the interval ../2008-08-23' do
172
+ let(:interval) { Date.edtf('../2008-08-23') }
173
+
174
+ it { expect(interval).to be_open }
175
+ it { expect(interval).to be_open_start }
176
+ it { expect(interval).not_to be_open_end }
177
+ it { expect(interval).not_to be_unknown }
178
+ it { expect(interval).not_to be_unknown_start }
179
+ it { expect(interval).not_to be_unknown_end }
180
+
181
+ it 'the max date is 2008-08-23' do
182
+ expect(interval.max).to eq(Date.new(2008,8,23))
183
+ end
184
+
185
+ it 'the min date is nil' do
186
+ expect(interval.min).to be nil
187
+ end
188
+
189
+ it 'includes christmas day 2007' do
190
+ expect(interval).to be_include(Date.new(2007,12,24))
191
+ end
192
+
193
+ it 'covers christmas day 2007' do
194
+ expect(interval).to be_cover(Date.new(2007,12,24))
195
+ end
196
+
197
+ it 'covers 2003-07-02' do
198
+ expect(interval).to be_cover(Date.new(2003,07,02))
199
+ end
200
+ end
201
+
109
202
  describe 'the interval 2008/unknown' do
110
203
  let(:interval) { Date.edtf('2008/unknown') }
111
204
 
@@ -126,6 +219,66 @@ module EDTF
126
219
  end
127
220
  end
128
221
 
222
+ describe 'the interval unknown/2008' do
223
+ let(:interval) { Date.edtf('unknown/2008') }
224
+
225
+ it { expect(interval).to be_unknown }
226
+ it { expect(interval).not_to be_unknown_end }
227
+ it { expect(interval).to be_unknown_start }
228
+
229
+ it 'the max date is 2008-12-31' do
230
+ expect(interval.max.to_s).to eq('2008-12-31')
231
+ end
232
+
233
+ it 'the max date has year precision' do
234
+ expect(interval.max).to be_year_precision
235
+ end
236
+
237
+ it 'the min date is nil' do
238
+ expect(interval.min).to be nil
239
+ end
240
+ end
241
+
242
+ describe 'the interval 2008/' do
243
+ let(:interval) { Date.edtf('2008/') }
244
+
245
+ it { expect(interval).to be_unknown }
246
+ it { expect(interval).to be_unknown_end }
247
+ it { expect(interval).not_to be_unknown_start }
248
+
249
+ it 'the min date is 2008-01-01' do
250
+ expect(interval.min.to_s).to eq('2008-01-01')
251
+ end
252
+
253
+ it 'the min date has year precision' do
254
+ expect(interval.min).to be_year_precision
255
+ end
256
+
257
+ it 'the max date is nil' do
258
+ expect(interval.max).to be nil
259
+ end
260
+ end
261
+
262
+ describe 'the interval /2008' do
263
+ let(:interval) { Date.edtf('/2008') }
264
+
265
+ it { expect(interval).to be_unknown }
266
+ it { expect(interval).not_to be_unknown_end }
267
+ it { expect(interval).to be_unknown_start }
268
+
269
+ it 'the max date is 2008-12-31' do
270
+ expect(interval.max.to_s).to eq('2008-12-31')
271
+ end
272
+
273
+ it 'the max date has year precision' do
274
+ expect(interval.max).to be_year_precision
275
+ end
276
+
277
+ it 'the min date is nil' do
278
+ expect(interval.min).to be nil
279
+ end
280
+ end
281
+
129
282
  describe 'comparisions' do
130
283
  it '2007/2009 should be greater than 2001/2002' do
131
284
  expect(Date.edtf('2007/2009')).to be > Date.edtf('2001/2002')
@@ -151,11 +304,5 @@ module EDTF
151
304
  expect(Date.edtf('2007/2009')).to eq(Date.edtf('2007/2009'))
152
305
  end
153
306
  end
154
-
155
- it 'may not have an open start' do
156
- expect {
157
- Interval.new(:open, Date.today)
158
- }.to raise_error(ArgumentError)
159
- end
160
307
  end
161
308
  end
@@ -78,5 +78,30 @@ module EDTF
78
78
  end
79
79
  end
80
80
 
81
+ describe 'the set [1760-12..1761-03]' do
82
+ let(:set) { Date.edtf('[1760-12..1761-03]') }
83
+
84
+ it "is a choice" do
85
+ expect(set).to be_choice
86
+ end
87
+
88
+ it "maps to the 4 months 1760-12 through 1761-03" do
89
+ expected_months = %w[1760-12 1761-01 1761-02 1761-03].map { |m| Date.edtf(m) }
90
+ expect(set.to_a).to eq(expected_months)
91
+ end
92
+ end
93
+
94
+ describe 'the set {1760-12..1761-03}' do
95
+ let(:set) { Date.edtf('{1760-12..1761-03}') }
96
+
97
+ it "is not a choice" do
98
+ expect(set).not_to be_choice
99
+ end
100
+
101
+ it "maps to the 4 months 1760-12 through 1761-03" do
102
+ expected_months = %w[1760-12 1761-01 1761-02 1761-03].map { |m| Date.edtf(m) }
103
+ expect(set.to_a).to eq(expected_months)
104
+ end
105
+ end
81
106
  end
82
107
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edtf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvester Keil
8
8
  - Ilja Srna
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-11-26 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
@@ -32,14 +31,12 @@ dependencies:
32
31
  - !ruby/object:Gem::Version
33
32
  version: '9.0'
34
33
  description: A Ruby implementation of the Extended Date/Time Format (EDTF).
35
- email:
36
34
  executables: []
37
35
  extensions: []
38
36
  extra_rdoc_files:
39
- - README.md
40
37
  - LICENSE
38
+ - README.md
41
39
  files:
42
- - ".autotest"
43
40
  - ".github/workflows/ci.yml"
44
41
  - ".gitignore"
45
42
  - ".rspec"
@@ -88,7 +85,6 @@ homepage: http://github.com/inukshuk/edtf-ruby
88
85
  licenses:
89
86
  - BSD-2-Clause-Views
90
87
  metadata: {}
91
- post_install_message:
92
88
  rdoc_options:
93
89
  - "--line-numbers"
94
90
  - "--inline-source"
@@ -110,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
106
  - !ruby/object:Gem::Version
111
107
  version: '0'
112
108
  requirements: []
113
- rubygems_version: 3.5.6
114
- signing_key:
109
+ rubygems_version: 4.0.10
115
110
  specification_version: 4
116
111
  summary: Extended Date/Time Format for Ruby.
117
112
  test_files:
data/.autotest DELETED
@@ -1,8 +0,0 @@
1
- require 'autotest/bundler'
2
-
3
- Autotest.add_hook :initialize do |at|
4
- at.add_mapping(/.+\.y$/) do |f,_|
5
- system 'rake clean racc_debug'
6
- end
7
- end
8
-