edtf 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/Gemfile +8 -3
- data/README.md +8 -8
- data/features/parser/date_times.feature +3 -3
- data/features/print/level_0_edtf.feature +61 -61
- data/features/step_definitions/edtf_steps.rb +25 -25
- data/features/support/env.rb +1 -1
- data/lib/edtf/date.rb +6 -3
- data/lib/edtf/date_time.rb +10 -1
- data/lib/edtf/parser.rb +344 -343
- data/lib/edtf/parser.y +29 -28
- data/lib/edtf/set.rb +3 -1
- data/lib/edtf/version.rb +1 -1
- data/spec/edtf/date_spec.rb +39 -39
- data/spec/edtf/epoch_spec.rb +15 -15
- data/spec/edtf/interval_spec.rb +35 -35
- data/spec/edtf/parser_spec.rb +123 -123
- data/spec/edtf/season_spec.rb +22 -21
- data/spec/edtf/set_spec.rb +71 -71
- data/spec/edtf/uncertainty_spec.rb +42 -42
- data/spec/spec_helper.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78ea9e9fd8f43b0113aadd9b17a62de265c11972
|
4
|
+
data.tar.gz: 14afd317d3146be4e5d2e4f9bfbf3cbf0c365856
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ae6ab55647c39ed69d384f7b3f82579d58ec6c9c156cc5c6f255d95660229dd518c13039f327e8839c163c126a997978cce9e5a54a170439e5875fa3ac8fafe
|
7
|
+
data.tar.gz: 45ce22b6fed0acfec4376094f05a75e7529fb33e28c8311f128451bbf4143498a627c67f62ec0a9e372f827650bf6ff607576a1a0c57f94a20168d2368d3cadf
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,7 +3,7 @@ gemspec
|
|
3
3
|
|
4
4
|
group :debug do
|
5
5
|
gem 'ruby-debug', :require => false, :platform => :jruby
|
6
|
-
gem '
|
6
|
+
gem 'byebug', :require => false, :platform => :mri
|
7
7
|
gem 'rubinius-compiler', '~>2.0', :require => false, :platform => :rbx
|
8
8
|
gem 'rubinius-debugger', '~>2.0', :require => false, :platform => :rbx
|
9
9
|
end
|
@@ -12,7 +12,7 @@ group :development do
|
|
12
12
|
gem 'rake'
|
13
13
|
gem 'racc', :platform => :ruby
|
14
14
|
gem 'cucumber'
|
15
|
-
gem 'rspec'
|
15
|
+
gem 'rspec', '~>3.0'
|
16
16
|
gem 'simplecov', '~>0.8', :require => false
|
17
17
|
gem 'rubinius-coverage', :platform => :rbx
|
18
18
|
gem 'coveralls', :require => false
|
@@ -26,6 +26,11 @@ end
|
|
26
26
|
gem 'i18n'
|
27
27
|
|
28
28
|
platform :rbx do
|
29
|
-
gem 'rubysl', '~>2.0'
|
29
|
+
gem 'rubysl-singleton', '~>2.0'
|
30
|
+
gem 'rubysl-open3', '~>2.0'
|
31
|
+
gem 'rubysl-enumerator', '~>2.0'
|
32
|
+
gem 'rubysl-base64', '~>2.0'
|
33
|
+
gem 'rubysl-bigdecimal', '~>2.0'
|
34
|
+
gem 'rubysl-drb', '~>2.0'
|
30
35
|
gem 'json'
|
31
36
|
end
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ EDTF-Ruby
|
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/inukshuk/edtf-ruby/badge.png)](https://coveralls.io/r/inukshuk/edtf-ruby)
|
5
5
|
|
6
6
|
EDTF-Ruby comprises a parser and an API implementation of the [Extended
|
7
|
-
Date/Time Format standard](http://www.loc.gov/standards/datetime/
|
7
|
+
Date/Time Format standard](http://www.loc.gov/standards/datetime/).
|
8
8
|
|
9
9
|
|
10
10
|
Compatibility
|
@@ -21,8 +21,8 @@ EDTF-Ruby parser implements all levels and features of the EDTF specification
|
|
21
21
|
examples, though).
|
22
22
|
|
23
23
|
EDTF-Ruby has been confirmed to work on the following Ruby implementations:
|
24
|
-
2.1, 2.0, 1.9.3, Rubinius, and JRuby (1.8.7 and 1.9.2 were originally
|
25
|
-
we are not testing compatibility actively anymore). Active Support's date
|
24
|
+
2.1, 2.0, 1.9.3, Rubinius, and JRuby (1.8.7 and 1.9.2 were originally supported
|
25
|
+
but we are not testing compatibility actively anymore). Active Support's date
|
26
26
|
extensions are currently listed as a dependency, because of many functional
|
27
27
|
overlaps (version 3.x and 4.x are supported).
|
28
28
|
|
@@ -63,10 +63,10 @@ precision to month, however, the natural successor is not the next day, but
|
|
63
63
|
a day a month from now. Always keep precision in mind when comparing dates,
|
64
64
|
too:
|
65
65
|
|
66
|
-
> Date.new(
|
66
|
+
> Date.new(1966).year_precision! == Date.new(1966)
|
67
67
|
=> false
|
68
68
|
|
69
|
-
The year
|
69
|
+
The year 1966 is not equal to the January 1st, 1966. You can set a date's
|
70
70
|
precision directly, or else use the dedicated bang! methods:
|
71
71
|
|
72
72
|
> d = Date.new(1993)
|
@@ -213,7 +213,7 @@ and the `choice` attribute.
|
|
213
213
|
=> false
|
214
214
|
> s.choice!
|
215
215
|
> s.edtf
|
216
|
-
=> "[1667,
|
216
|
+
=> "[1667,1668,1670..1672]"
|
217
217
|
|
218
218
|
As you can see above, EDTF-Ruby remembers which parts of the set were
|
219
219
|
specified as a range; ranges are however enumerated for membership tests:
|
@@ -233,7 +233,7 @@ When in doubt, you can always map the set to an array. This will also
|
|
233
233
|
enumerate all ranges:
|
234
234
|
|
235
235
|
> s.map(&:year)
|
236
|
-
=> [1667,
|
236
|
+
=> [1667,1668,1670,1671,1672] # when enumerated there are 5 elements
|
237
237
|
|
238
238
|
EDTF sets also feature an `#earlier?` and `#later?` attribute:
|
239
239
|
|
@@ -241,7 +241,7 @@ EDTF sets also feature an `#earlier?` and `#later?` attribute:
|
|
241
241
|
=> false
|
242
242
|
> s.earlier!
|
243
243
|
> s.edtf
|
244
|
-
=> "[..1667,
|
244
|
+
=> "[..1667,1668,1670..1672]"
|
245
245
|
|
246
246
|
|
247
247
|
### Decades and Centuries
|
@@ -2,7 +2,7 @@ Feature: EDTF parses date/time strings
|
|
2
2
|
|
3
3
|
As a user of edtf-ruby
|
4
4
|
I want to parse date/time strings formatted in EDTF
|
5
|
-
|
5
|
+
|
6
6
|
Scenario Outline: EDTF parses a date/time string
|
7
7
|
When I parse the string "<string>"
|
8
8
|
Then the year should be "<year>"
|
@@ -33,9 +33,9 @@ Feature: EDTF parses date/time strings
|
|
33
33
|
| 2004-01-01T10:10:10Z | 2004 | 1 | 1 | 10 | 10 | 10 |
|
34
34
|
| 2004-01-01T10:10:10+05:00 | 2004 | 1 | 1 | 5 | 10 | 10 |
|
35
35
|
| 2004-01-01T02:10:10+05:00 | 2003 | 12 | 31 | 21 | 10 | 10 |
|
36
|
-
|
36
|
+
|
37
37
|
# Scenarios: fractions
|
38
38
|
# | string | year | month | day | hours | minutes | seconds |
|
39
39
|
# | 2004-01-01T10 | 2004 | 1 | 1 | 10 | 0 | 0 |
|
40
40
|
# | 2004-01-01T10:10:10+05:00 | 2004 | 1 | 1 | 5 | 10 | 10 |
|
41
|
-
# | 2004-01-01T02:10:10+05:00 | 2003 | 12 | 31 | 21 | 10 | 10 |
|
41
|
+
# | 2004-01-01T02:10:10+05:00 | 2003 | 12 | 31 | 21 | 10 | 10 |
|
@@ -1,73 +1,73 @@
|
|
1
1
|
Feature: Print Date/Time objects as Level 0 EDTF strings
|
2
2
|
As a Ruby programmer
|
3
3
|
I want to convert Date/Time objects to EDTF strings
|
4
|
-
|
4
|
+
|
5
5
|
@001 @level0
|
6
6
|
Scenario: Convert simple dates
|
7
7
|
Given the date "2004-08-12"
|
8
8
|
When I convert the date
|
9
9
|
Then the EDTF string should be "2004-08-12"
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
@001 @level0
|
12
|
+
Scenario: Convert simple dates with precision
|
13
|
+
Given the date "1980-08-24" with precision set to "day"
|
14
|
+
When I convert the date
|
15
|
+
Then the EDTF string should be "1980-08-24"
|
16
|
+
Given the date "1980-08-24" with precision set to "month"
|
17
|
+
When I convert the date
|
18
|
+
Then the EDTF string should be "1980-08"
|
19
|
+
Given the date "1980-08-24" with precision set to "year"
|
20
|
+
When I convert the date
|
21
|
+
Then the EDTF string should be "1980"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
23
|
+
@001 @level0
|
24
|
+
Scenario: Date Roundtrips
|
25
|
+
When I parse the string "2001-02-03"
|
26
|
+
When I convert the date
|
27
|
+
Then the EDTF string should be "2001-02-03"
|
28
|
+
When I parse the string "2001-02"
|
29
|
+
When I convert the date
|
30
|
+
Then the EDTF string should be "2001-02"
|
31
|
+
When I parse the string "2001"
|
32
|
+
When I convert the date
|
33
|
+
Then the EDTF string should be "2001"
|
34
|
+
When I parse the string "-9909"
|
35
|
+
When I convert the date
|
36
|
+
Then the EDTF string should be "-9909"
|
37
|
+
When I parse the string "0000"
|
38
|
+
When I convert the date
|
39
|
+
Then the EDTF string should be "0000"
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
41
|
+
@002 @level0
|
42
|
+
Scenario: DateTime Roundtrips
|
43
|
+
When I parse the string "2001-02-03T09:30:01"
|
44
|
+
When I convert the date
|
45
|
+
Then the EDTF string should be "2001-02-03T09:30:01"
|
46
|
+
When I parse the string "2004-01-01T10:10:10Z"
|
47
|
+
When I convert the date
|
48
|
+
Then the EDTF string should be "2004-01-01T10:10:10+00:00"
|
49
|
+
When I parse the string "2004-01-01T10:10:10+05:00"
|
50
|
+
When I convert the date
|
51
|
+
Then the EDTF string should be "2004-01-01T10:10:10+05:00"
|
52
|
+
|
53
|
+
@004 @level0
|
54
|
+
Scenario: Interval Roundtrips
|
55
|
+
When I parse the string "1964/2008"
|
56
|
+
When I convert the date
|
57
|
+
Then the EDTF string should be "1964/2008"
|
58
|
+
When I parse the string "2004-06/2006-08"
|
59
|
+
When I convert the date
|
60
|
+
Then the EDTF string should be "2004-06/2006-08"
|
61
|
+
When I parse the string "2004-02-01/2005-02-08"
|
62
|
+
When I convert the date
|
63
|
+
Then the EDTF string should be "2004-02-01/2005-02-08"
|
64
|
+
When I parse the string "2004-02-01/2005-02"
|
65
|
+
When I convert the date
|
66
|
+
Then the EDTF string should be "2004-02-01/2005-02"
|
67
|
+
When I parse the string "2004-02-01/2005"
|
68
|
+
When I convert the date
|
69
|
+
Then the EDTF string should be "2004-02-01/2005"
|
70
|
+
When I parse the string "2005/2006-02"
|
71
|
+
When I convert the date
|
72
|
+
Then the EDTF string should be "2005/2006-02"
|
52
73
|
|
53
|
-
@004 @level0
|
54
|
-
Scenario: Interval Roundtrips
|
55
|
-
When I parse the string "1964/2008"
|
56
|
-
When I convert the date
|
57
|
-
Then the EDTF string should be "1964/2008"
|
58
|
-
When I parse the string "2004-06/2006-08"
|
59
|
-
When I convert the date
|
60
|
-
Then the EDTF string should be "2004-06/2006-08"
|
61
|
-
When I parse the string "2004-02-01/2005-02-08"
|
62
|
-
When I convert the date
|
63
|
-
Then the EDTF string should be "2004-02-01/2005-02-08"
|
64
|
-
When I parse the string "2004-02-01/2005-02"
|
65
|
-
When I convert the date
|
66
|
-
Then the EDTF string should be "2004-02-01/2005-02"
|
67
|
-
When I parse the string "2004-02-01/2005"
|
68
|
-
When I convert the date
|
69
|
-
Then the EDTF string should be "2004-02-01/2005"
|
70
|
-
When I parse the string "2005/2006-02"
|
71
|
-
When I convert the date
|
72
|
-
Then the EDTF string should be "2005/2006-02"
|
73
|
-
|
@@ -8,7 +8,7 @@ When /^I convert the date$/ do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
Then /^the EDTF String should be "([^"]*)"$/i do |edtf|
|
11
|
-
@string.
|
11
|
+
expect(@string).to eq(edtf)
|
12
12
|
end
|
13
13
|
|
14
14
|
When /^I parse the string "([^"]*)"$/ do |string|
|
@@ -16,102 +16,102 @@ When /^I parse the string "([^"]*)"$/ do |string|
|
|
16
16
|
end
|
17
17
|
|
18
18
|
Then /^the year should be "([^"]*)"$/ do |year|
|
19
|
-
@date.year.
|
19
|
+
expect(@date.year).to eq(year.to_i)
|
20
20
|
end
|
21
21
|
|
22
22
|
Then /^the month should be "([^"]*)"$/ do |month|
|
23
|
-
@date.month.
|
23
|
+
expect(@date.month).to eq(month.to_i)
|
24
24
|
end
|
25
25
|
|
26
26
|
Then /^the day should be "([^"]*)"$/ do |day|
|
27
|
-
@date.day.
|
27
|
+
expect(@date.day).to eq(day.to_i)
|
28
28
|
end
|
29
29
|
|
30
30
|
Then /^the hours should be "([^"]*)"$/ do |hours|
|
31
|
-
@date.hour.
|
31
|
+
expect(@date.hour).to eq(hours.to_i)
|
32
32
|
end
|
33
33
|
|
34
34
|
Then /^the year should be "([^"]*)" \(UTC\)$/ do |year|
|
35
|
-
@date.to_time.utc.year.
|
35
|
+
expect(@date.to_time.utc.year).to eq(year.to_i)
|
36
36
|
end
|
37
37
|
|
38
38
|
Then /^the month should be "([^"]*)" \(UTC\)$/ do |month|
|
39
|
-
@date.to_time.utc.month.
|
39
|
+
expect(@date.to_time.utc.month).to eq(month.to_i)
|
40
40
|
end
|
41
41
|
|
42
42
|
Then /^the day should be "([^"]*)" \(UTC\)$/ do |day|
|
43
|
-
@date.to_time.utc.day.
|
43
|
+
expect(@date.to_time.utc.day).to eq(day.to_i)
|
44
44
|
end
|
45
45
|
|
46
46
|
Then /^the hours should be "([^"]*)" \(UTC\)$/ do |hours|
|
47
|
-
@date.to_time.utc.hour.
|
47
|
+
expect(@date.to_time.utc.hour).to eq(hours.to_i)
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
51
|
Then /^the minutes should be "([^"]*)"$/ do |minutes|
|
52
|
-
@date.min.
|
52
|
+
expect(@date.min).to eq(minutes.to_i)
|
53
53
|
end
|
54
54
|
|
55
55
|
Then /^the seconds should be "([^"]*)"$/ do |seconds|
|
56
|
-
@date.sec.
|
56
|
+
expect(@date.sec).to eq(seconds.to_i)
|
57
57
|
end
|
58
58
|
|
59
59
|
Then /^the duration should range from "([^"]*)" to "([^"]*)"$/ do |from,to|
|
60
|
-
[@date.begin.year.to_s, @date.end.year.to_s].
|
60
|
+
expect([@date.begin.year.to_s, @date.end.year.to_s]).to eq([from,to])
|
61
61
|
end
|
62
62
|
|
63
63
|
Then /^the interval should start at "([^"]*)"$/ do |date|
|
64
|
-
@date.begin.to_s.
|
64
|
+
expect(@date.begin.to_s).to eq(date)
|
65
65
|
end
|
66
66
|
|
67
67
|
Then /^the interval should end at "([^"]*)"$/ do |date|
|
68
|
-
@date.end.to_s.
|
68
|
+
expect(@date.end.to_s).to eq(date)
|
69
69
|
end
|
70
70
|
|
71
71
|
Then /^the interval should include the date "([^"]*)"$/ do |date|
|
72
|
-
@date.
|
72
|
+
expect(@date).to include(Date.parse(date))
|
73
73
|
end
|
74
74
|
|
75
75
|
Then /^the interval should cover the date "([^"]*)"$/ do |date|
|
76
|
-
@date.
|
76
|
+
expect(@date).to be_cover(Date.parse(date))
|
77
77
|
end
|
78
78
|
|
79
79
|
|
80
80
|
Then /^the date should be uncertain\? "([^"]*)"$/ do |arg1|
|
81
|
-
@date.uncertain
|
81
|
+
expect(@date.uncertain?).to eq(!!(arg1 =~ /y(es)?/i))
|
82
82
|
end
|
83
83
|
|
84
84
|
Then /^the year should be uncertain\? "([^"]*)"$/ do |arg1|
|
85
|
-
@date.uncertain?(:year).
|
85
|
+
expect(@date.uncertain?(:year)).to eq(!!(arg1 =~ /y(es)?/i))
|
86
86
|
end
|
87
87
|
|
88
88
|
Then /^the month should be uncertain\? "([^"]*)"$/ do |arg1|
|
89
|
-
@date.uncertain?(:month).
|
89
|
+
expect(@date.uncertain?(:month)).to eq(!!(arg1 =~ /y(es)?/i))
|
90
90
|
end
|
91
91
|
|
92
92
|
Then /^the day should be uncertain\? "([^"]*)"$/ do |arg1|
|
93
|
-
@date.uncertain?(:day).
|
93
|
+
expect(@date.uncertain?(:day)).to eq(!!(arg1 =~ /y(es)?/i))
|
94
94
|
end
|
95
95
|
|
96
96
|
Then /^the date should be approximate\? "([^"]*)"$/ do |arg1|
|
97
|
-
@date.approximate
|
97
|
+
expect(@date.approximate?).to eq(!!(arg1 =~ /y(es)?/i))
|
98
98
|
end
|
99
99
|
|
100
100
|
Then /^the year should be approximate\? "([^"]*)"$/ do |arg1|
|
101
|
-
@date.approximate?(:year).
|
101
|
+
expect(@date.approximate?(:year)).to eq(!!(arg1 =~ /y(es)?/i))
|
102
102
|
end
|
103
103
|
|
104
104
|
Then /^the month should be approximate\? "([^"]*)"$/ do |arg1|
|
105
|
-
@date.approximate?(:month).
|
105
|
+
expect(@date.approximate?(:month)).to eq(!!(arg1 =~ /y(es)?/i))
|
106
106
|
end
|
107
107
|
|
108
108
|
Then /^the day should be approximate\? "([^"]*)"$/ do |arg1|
|
109
|
-
@date.approximate?(:day).
|
109
|
+
expect(@date.approximate?(:day)).to eq(!!(arg1 =~ /y(es)?/i))
|
110
110
|
end
|
111
111
|
|
112
112
|
|
113
113
|
Then /^the unspecified string code be "([^"]*)"$/ do |arg1|
|
114
|
-
@date.unspecified.to_s.
|
114
|
+
expect(@date.unspecified.to_s).to eq(arg1)
|
115
115
|
end
|
116
116
|
|
117
117
|
When /^I parse the following strings an error should be raised:$/ do |table|
|
data/features/support/env.rb
CHANGED
data/lib/edtf/date.rb
CHANGED
@@ -13,7 +13,7 @@ class Date
|
|
13
13
|
}.freeze
|
14
14
|
|
15
15
|
EXTENDED_ATTRIBUTES = %w{
|
16
|
-
calendar precision uncertain approximate unspecified
|
16
|
+
calendar precision uncertain approximate unspecified skip_timezone
|
17
17
|
}.map(&:to_sym).freeze
|
18
18
|
|
19
19
|
extend Forwardable
|
@@ -31,7 +31,7 @@ class Date
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
attr_accessor :calendar
|
34
|
+
attr_accessor :calendar, :skip_timezone
|
35
35
|
|
36
36
|
PRECISION.each do |p|
|
37
37
|
define_method("#{p}_precision?") { precision == p }
|
@@ -162,6 +162,9 @@ class Date
|
|
162
162
|
# Returns true if the Date has an EDTF calendar string attached.
|
163
163
|
def calendar?; !!@calendar; end
|
164
164
|
|
165
|
+
# Returns true if the Date's EDTF string should be printed without timezone.
|
166
|
+
def skip_timezone?; !!@skip_timezone; end
|
167
|
+
|
165
168
|
# Converts the Date into a season.
|
166
169
|
def season
|
167
170
|
Season.new(self)
|
@@ -192,7 +195,7 @@ class Date
|
|
192
195
|
y << SYMBOLS[:approximate] if 24&h==8 || 27&h==26
|
193
196
|
|
194
197
|
|
195
|
-
# combine if false-true-true and other m == d
|
198
|
+
# combine if false-true-true and other m == d
|
196
199
|
if 7&h==6 && (48&h==48 || 48&h==0) || 56&h==48 && (6&h==6 || 6&h==0)
|
197
200
|
m[0,0] = '('
|
198
201
|
d << ')'
|