edtf 3.0.1 → 3.0.2

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.
@@ -20,18 +20,12 @@ rule
20
20
  | date_time
21
21
  ;
22
22
 
23
- date : positive_date
24
- | negative_date
25
- ;
26
-
27
- positive_date :
23
+ date :
28
24
  year { result = Date.new(val[0]).year_precision! }
29
25
  | year_month { result = Date.new(*val.flatten).month_precision! }
30
26
  | year_month_day { result = Date.new(*val.flatten).day_precision! }
31
27
  ;
32
28
 
33
- negative_date : '-' positive_date { result = -val[1] }
34
-
35
29
 
36
30
  date_time : date T time {
37
31
  result = DateTime.new(val[0].year, val[0].month, val[0].day, *val[2])
@@ -61,7 +55,10 @@ rule
61
55
  | '0' '0' ':' d01_59 { result = Rational(val[3], 1440) }
62
56
  ;
63
57
 
64
- year : digit digit digit digit {
58
+ year : positive_year
59
+ | '-' positive_year { result = -val[1] }
60
+
61
+ positive_year : digit digit digit digit {
65
62
  result = val.zip([1000,100,10,1]).reduce(0) { |s,(a,b)| s += a * b }
66
63
  }
67
64
 
@@ -108,7 +105,14 @@ rule
108
105
  | unspecified_day_and_month
109
106
  ;
110
107
 
111
- unspecified_year :
108
+ unspecified_year : positive_unspecified_year
109
+ | '-' positive_unspecified_year
110
+ {
111
+ result = val[1]
112
+ result[0] = -result[0]
113
+ }
114
+
115
+ positive_unspecified_year :
112
116
  digit digit digit U
113
117
  {
114
118
  result = [val[0,3].zip([1000,100,10]).reduce(0) { |s,(a,b)| s += a * b }, [false,true]]
@@ -1,3 +1,3 @@
1
1
  module EDTF
2
- VERSION = '3.0.1'.freeze
2
+ VERSION = '3.0.2'.freeze
3
3
  end
@@ -50,7 +50,12 @@ module EDTF
50
50
  expect(Parser.new.parse('199u')).to be_unspecified
51
51
  expect(Parser.new.parse('1999-uu-uu')).to be_unspecified
52
52
  end
53
-
53
+
54
+ it 'parses negative unspecified dates' do
55
+ expect(Parser.new.parse('-199u')).to be_unspecified
56
+ expect(Parser.new.parse('-1999-uu-uu')).to be_unspecified
57
+ end
58
+
54
59
  it 'parses open intervals' do
55
60
  expect(Parser.new.parse('2004-01-01/open')).to be_open
56
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edtf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvester Keil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-17 00:00:00.000000000 Z
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport