parse_date 0.3.3 → 0.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42b7b5f7405ee4a79e7eece920b10fe2852a03c996b32da8c2b8edc58a6e3ede
4
- data.tar.gz: eeba668fd1ee75994f743a010dbe37af4ffdcb8ca0c4143ca329c811739c4b28
3
+ metadata.gz: c818fd11526f5dbddb22a29801089a6ff9946d0eb23a208af5316a34c2201836
4
+ data.tar.gz: bb5b1f93425fe42659b144554b8a21dc95615a7b7e35ac1a361d7696869367f1
5
5
  SHA512:
6
- metadata.gz: a22f1e23899efc15e5fd13ab1aac724cddc39ddf9986d0295e2f4360b639483da116ef4540bb35fc0c03cf201c0d29f4e0ac6729339140663ff7622ed8a7a623
7
- data.tar.gz: df518ca44ed63ea2925976fe49a11e28cd4ecc40b66752c7db11934d4bba6fe7ade795aca93402cb0f556816cf076e40006e08294162b8f01c527377a4603e51
6
+ metadata.gz: 5b8f75b733e86e4f6f6178279a7959a6693443ddd2bb0c1315957b3d197993c2bd19790516f5170b6458f0ae4209ce3bf8b9e83fdb9b30b373e0bf2896aed93d
7
+ data.tar.gz: a3adec7a2979f591386a9674f7d096f70dc9146af27ed3b734404f195fa35c820b5218a850365ac386a6d478cc71bf7b7f1d78ffcdf523d6d4547b3d52caeff3
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-10-28 09:19:23 -0700 using RuboCop version 0.74.0.
3
+ # on 2019-10-28 20:35:55 -0700 using RuboCop version 0.74.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -17,7 +17,7 @@ Metrics/CyclomaticComplexity:
17
17
  # Offense count: 1
18
18
  # Configuration parameters: CountComments.
19
19
  Metrics/ModuleLength:
20
- Max: 178
20
+ Max: 183
21
21
 
22
22
  # Offense count: 4
23
23
  Metrics/PerceivedComplexity:
data/README.md CHANGED
@@ -52,13 +52,18 @@ ParseDate.parse_range('17--?-18--?') # (1700..1899).to_a
52
52
  ParseDate.parse_range('1835 or 1836') # [1835, 1836]
53
53
  ParseDate.parse_range('17-- or 18--?') # (1700..1899).to_a
54
54
  ParseDate.parse_range('-2 or 1?') # (-2..1).to_a
55
+ ParseDate.parse_range('1500? to 1582') # (1500..1582).to_a
55
56
  ParseDate.parse_range('17th or 18th century?') # (1600..1799).to_a
56
57
  ParseDate.parse_range('ca. 5th–6th century A.D.') # (400..599).to_a
57
58
  ParseDate.parse_range('ca. 9th–8th century B.C.') # (-999..-800).to_a
58
59
  ParseDate.parse_range('ca. 13th–12th century B.C.') # (-1399..-1200).to_a
59
60
  ParseDate.parse_range('5th century B.C.') # (-599..-500).to_a
60
61
  ParseDate.parse_range('502-504') # [502, 503, 504]
62
+ ParseDate.parse_range('950-60') # (950..960).to_a
63
+ ParseDate.parse_range('-0150 - -0100') # (-150..-100).to_a
61
64
  ParseDate.parse_range('-2100 - -2000') # (-2100..-2000).to_a
65
+ ParseDate.parse_range('1230—1239 CE') # (1230..1239).to_a (alternate hyphen char)
66
+ ParseDate.parse_range('996–1021 CE') # (996..1021).to_a (diff alternate hyphen char)
62
67
  ParseDate.parse_range('1975 - 1905') # last year > first year, raises error
63
68
  ParseDate.parse_range('-100 - -150') # last year > first year, raises error
64
69
  ParseDate.parse_range('1975 or 1905') # last year > first year, raises error
@@ -82,7 +87,10 @@ ParseDate.earliest_year('17uu') # 1700
82
87
  ParseDate.earliest_year('between 1694 and 1799') # 1694
83
88
  ParseDate.earliest_year('between 1 and 5') # 1
84
89
  ParseDate.earliest_year('between 300 and 150 B.C.') # -300
90
+ ParseDate.earliest_year('1500? to 1582') # 1500
85
91
  ParseDate.earliest_year('1496-1499') # 1496
92
+ ParseDate.earliest_year('1230—1239 CE') # 1230 (alternate hyphen char)
93
+ ParseDate.earliest_year('996–1021 CE') # 996 (diff alternate hyphen char)
86
94
  ParseDate.earliest_year('1750?-1867') # 1750
87
95
  ParseDate.earliest_year('17--?-18--?') # 1700
88
96
  ParseDate.earliest_year('1835 or 1836') # 1835
@@ -93,6 +101,8 @@ ParseDate.earliest_year('ca. 9th–8th century B.C.') # -999
93
101
  ParseDate.earliest_year('ca. 13th–12th century B.C.') # -1399
94
102
  ParseDate.earliest_year('5th century B.C.') # -599
95
103
  ParseDate.earliest_year('502-504') # 502
104
+ ParseDate.earliest_year('950-60') # 950
105
+ ParseDate.earliest_year('-0150 - -0100') # -150
96
106
  ParseDate.earliest_year('-2100 - -2000') # -2100
97
107
 
98
108
  ParseDate.latest_year('20000222') # 2000
@@ -105,7 +115,10 @@ ParseDate.latest_year('17uu') # 1799
105
115
  ParseDate.latest_year('between 1694 and 1799') # 1799
106
116
  ParseDate.latest_year('between 1 and 5') # 5
107
117
  ParseDate.latest_year('between 300 and 150 B.C.') # -150
118
+ ParseDate.latest_year('1500? to 1582') # 1582
108
119
  ParseDate.latest_year('1496-1499') # 1499
120
+ ParseDate.latest_year('1230—1239 CE') # 1239 (alternate hyphen char)
121
+ ParseDate.latest_year('996–1021 CE') # 1021 (diff alternate hyphen char)
109
122
  ParseDate.latest_year('1750?-1867') # 1867
110
123
  ParseDate.latest_year('17--?-18--?') # 1899
111
124
  ParseDate.latest_year('1757-58') # 1758
@@ -119,6 +132,8 @@ ParseDate.latest_year('ca. 13th–12th century B.C.') # -1200
119
132
  ParseDate.latest_year('5th century B.C.') # -500
120
133
  ParseDate.latest_year('-5 - 3') # 3
121
134
  ParseDate.latest_year('502-504') # 504
135
+ ParseDate.latest_year('950-60') # 960
136
+ ParseDate.latest_year('-0150 - -0100') # -100
122
137
  ParseDate.latest_year('-2100 - -2000') # -2000
123
138
 
124
139
  ParseDate.range_array('1993', '1995') # [1993, 1994, 1995]
@@ -25,6 +25,7 @@ class ParseDate
25
25
  return ParseDate.send(:year_int_for_bc, date_str) if date_str.match(YEAR_BC_REGEX)
26
26
 
27
27
  result ||= ParseDate.send(:between_earliest_year, date_str)
28
+ result ||= ParseDate.send(:hyphen_4digit_earliest_year, date_str)
28
29
  result ||= ParseDate.send(:negative_first_four_digits, date_str)
29
30
  result ||= ParseDate.send(:first_four_digits, date_str)
30
31
  result ||= ParseDate.send(:year_from_mm_dd_yy, date_str)
@@ -97,7 +98,13 @@ class ParseDate
97
98
  date_str.delete('[]') if date_str.match(BRACKETS_BETWEEN_DIGITS_REGEX)
98
99
  end
99
100
 
100
- YYYY_HYPHEN_YYYY_REGEX = Regexp.new(/(?<first>\d{4})\??\s*[-—]\s*(?<last>\d{4})\??/m)
101
+ YYYY_HYPHEN_YYYY_REGEX = Regexp.new(/(?<first>\d{3,4})\??\s*(-|—|–|to)\s*(?<last>\d{4})\??/m)
102
+
103
+ # Integer value for latest year if we have "yyyy-yyyy" pattern
104
+ # @return [Integer, nil] yyyy if date_str matches pattern; nil otherwise
105
+ def hyphen_4digit_earliest_year(date_str)
106
+ Regexp.last_match(:first).to_i if date_str.match(YYYY_HYPHEN_YYYY_REGEX)
107
+ end
101
108
 
102
109
  # Integer value for latest year if we have "yyyy-yyyy" pattern
103
110
  # @return [Integer, nil] yyyy if date_str matches pattern; nil otherwise
@@ -105,7 +112,7 @@ class ParseDate
105
112
  Regexp.last_match(:last).to_i if date_str.match(YYYY_HYPHEN_YYYY_REGEX)
106
113
  end
107
114
 
108
- YYYY_HYPHEN_YY_REGEX = Regexp.new(/(?<first>\d{4})\??\s*[-—]\s*(?<last>\d{2})\??([^-0-9].*)?$/)
115
+ YYYY_HYPHEN_YY_REGEX = Regexp.new(/(?<first>\d{3,4})\??\s*(-|—|–|to)\s*(?<last>\d{2})\??([^-0-9].*)?$/)
109
116
 
110
117
  # Integer value for latest year if we have "yyyy-yy" pattern
111
118
  # @return [Integer, nil] yyyy if date_str matches pattern; nil otherwise
@@ -114,14 +121,14 @@ class ParseDate
114
121
  return unless matches
115
122
 
116
123
  first = Regexp.last_match(:first)
117
- century = first[0, 2]
124
+ century = first[0..-3] # whatever is before the last 2 digits
118
125
  last = "#{century}#{Regexp.last_match(:last)}"
119
126
  last.to_i if ParseDate.year_range_valid?(first.to_i, last.to_i)
120
127
  end
121
128
 
122
129
  YYUU = '\\d{1,2}[u\\-]{2}'
123
130
  YYuu_HYPHEN_YYuu_REGEX =
124
- Regexp.new("(?<first>#{YYUU})\\??\\s*[-—]\\s*(?<last>#{YYUU})\\??([^u\\-]|$)??", REGEX_OPTS)
131
+ Regexp.new("(?<first>#{YYUU})\\??\\s*(-|—|–|to)\\s*(?<last>#{YYUU})\\??([^u\\-]|$)??", REGEX_OPTS)
125
132
 
126
133
  # Integer value for latest year if we have "yyuu-yyuu" pattern
127
134
  # @return [Integer, nil] yyyy if date_str matches pattern; nil otherwise
@@ -139,7 +146,8 @@ class ParseDate
139
146
  end
140
147
 
141
148
  # NOTE: some actual data seemed to have a diff hyphen char. (slightly longer)
142
- YY_YY_CENTURY_REGEX = Regexp.new(/(?<first>\d{1,2})[a-z]{2}?\s*(-|–|or)\s*(?<last>\d{1,2})[a-z]{2}?\s+centur.*/im)
149
+ YY_YY_CENTURY_REGEX =
150
+ Regexp.new(/(?<first>\d{1,2})[a-z]{2}?\s*(-|–|–|or|to)\s*(?<last>\d{1,2})[a-z]{2}?\s+centur.*/im)
143
151
 
144
152
  # Integer value for latest year if we have nth-nth century pattern
145
153
  # @return [Integer, nil] yy99 if date_str matches pattern; nil otherwise
@@ -182,7 +190,7 @@ class ParseDate
182
190
  # looks for -yyyy after hyphen and returns if found
183
191
  # @return [String, nil] negative 4 digit year (e.g. -1865) if date_str has -yyyy - -yyyy, nil otherwise
184
192
  def negative_4digits_after_hyphen(date_str)
185
- Regexp.last_match(1) if date_str.match(/\-\d{4}\s*\-\s*(\-\d{4})/)
193
+ Regexp.last_match(1) if date_str.match(/\-\d{4}\s*(?:-|–|–|or|to)\s*(\-\d{4})/)
186
194
  end
187
195
 
188
196
  # looks for 4 consecutive digits in date_str and returns first occurrence if found
@@ -304,7 +312,7 @@ class ParseDate
304
312
  end
305
313
 
306
314
  FIRST_LAST_EARLY_NUMERIC_REGEX =
307
- Regexp.new(/^(?<first>\-?\d{1,3})\??\s*(-|–|or)\s*(?<last>\-?\d{1,4})\??([^\du\-\[]|$)/im)
315
+ Regexp.new(/^(?<first>\-?\d{1,3})\??\s*(-|–|–|or|to)\s*(?<last>\-?\d{1,4})\??([^\du\-\[]|$)/im)
308
316
 
309
317
  # Integer value for latest year if we have early numeric year range or single early numeric year
310
318
  # @return [Integer, nil] year if date_str matches pattern; nil otherwise
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ParseDate
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2019-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk