parse_date 0.4.0 → 0.4.1

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
  SHA256:
3
- metadata.gz: 367f2e3cc7710655783c53692b76d6c483be5dd197047b0a285857c2e8b29b10
4
- data.tar.gz: 37da36fa61807abcc852bb1dc4c5f4f05313dc87e25ad6d03db7a3f64da34998
3
+ metadata.gz: 36071ca61e644a7abfeb616a883260772c05498c06d9d8974bd6bc077147397c
4
+ data.tar.gz: 13c12acb9740c601876cbde4ab46ef4a7b966b9bc2d9471481d7ab2cad29d52d
5
5
  SHA512:
6
- metadata.gz: 31a6ec4a2b621f6689ecc4151f7809e3fc861a491382117350f2b9404db6f6c753206dc263d028b04a54aaa23b14c8cfcf036d3de7139d1f61dd3a3fdfb07d6e
7
- data.tar.gz: 289196806a4c8acba6904525adb65e5afe429dd5ee74acfb9ae75ea30980bc52f0ef1112871f948e0cd0454a9e0b303ac407b030d4562f8eac898cf3f8f5a6fe
6
+ metadata.gz: d7e538ce28565ddcc358f3985c540280bfde3703cf8b94c6debf830fbc27c9dda3639f325a0ad94cd70073d027c1a0b2d68ff8e32552a1b1a16274ca18b2644a
7
+ data.tar.gz: 21d322b522ada492336e0d521a38f17fabb118010b025b0e4f81e9e405b74533db468304e01100d841bfbba82fc194015f7e5040085ba4b65a1d0c1e9b87e8f5
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 20:35:55 -0700 using RuboCop version 0.74.0.
3
+ # on 2019-11-05 16:05:23 -0800 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
@@ -8,7 +8,7 @@
8
8
 
9
9
  # Offense count: 5
10
10
  Metrics/AbcSize:
11
- Max: 41
11
+ Max: 43
12
12
 
13
13
  # Offense count: 4
14
14
  Metrics/CyclomaticComplexity:
@@ -17,7 +17,7 @@ Metrics/CyclomaticComplexity:
17
17
  # Offense count: 1
18
18
  # Configuration parameters: CountComments.
19
19
  Metrics/ModuleLength:
20
- Max: 183
20
+ Max: 195
21
21
 
22
22
  # Offense count: 4
23
23
  Metrics/PerceivedComplexity:
data/README.md CHANGED
@@ -40,6 +40,12 @@ ParseDate.parse_range('195-') # (1950..1959).to_a
40
40
  ParseDate.parse_range('199u') # (1990..1999).to_a
41
41
  ParseDate.parse_range('197?') # (1970..1979).to_a
42
42
  ParseDate.parse_range('196x') # (1960..1969).to_a
43
+ ParseDate.parse_range('1990s') # (1990..1999).to_a
44
+ ParseDate.parse_range('1990s?') # (1990..1999).to_a
45
+ ParseDate.parse_range('ca. 1930s') # (1930..1939).to_a
46
+ ParseDate.parse_range('1928-1980s') # (1928..1989).to_a
47
+ ParseDate.parse_range('1940s-1990') # (1940..1990).to_a
48
+ ParseDate.parse_range('1980s-1990s') # (1980..1999).to_a
43
49
  ParseDate.parse_range('18th century CE') # (1700..1799).to_a
44
50
  ParseDate.parse_range('17uu') # (1700..1799).to_a
45
51
  ParseDate.parse_range('between 1694 and 1799') # (1694..1799).to_a
@@ -112,6 +118,12 @@ ParseDate.latest_year('195-') # 1959
112
118
  ParseDate.latest_year('199u') # 1999
113
119
  ParseDate.latest_year('197?') # 1979
114
120
  ParseDate.latest_year('196x') # 1969
121
+ ParseDate.latest_year('1990s') # 1999
122
+ ParseDate.latest_year('1990s?') # 1999
123
+ ParseDate.latest_year('ca. 1930s') # 1939
124
+ ParseDate.latest_year('1928-1980s') # 1989
125
+ ParseDate.latest_year('1940s-1990') # 1990
126
+ ParseDate.latest_year('1980s-1990s') # 1999
115
127
  ParseDate.latest_year('18th century CE') # 1799
116
128
  ParseDate.latest_year('17uu') # 1799
117
129
  ParseDate.latest_year('between 1694 and 1799') # 1799
@@ -65,6 +65,7 @@ class ParseDate
65
65
  result ||= ParseDate.send(:year_after_or, date_str)
66
66
  result ||= ParseDate.send(:negative_4digits_after_hyphen, date_str)
67
67
  result ||= ParseDate.send(:negative_first_four_digits, date_str)
68
+ result ||= ParseDate.send(:last_year_for_0s_decade, date_str)
68
69
  result ||= ParseDate.send(:first_four_digits, date_str)
69
70
  result ||= ParseDate.send(:year_from_mm_dd_yy, date_str)
70
71
  result ||= ParseDate.send(:last_year_for_decade, date_str) # 198x or 201x
@@ -98,7 +99,7 @@ class ParseDate
98
99
  date_str.delete('[]') if date_str.match(BRACKETS_BETWEEN_DIGITS_REGEX)
99
100
  end
100
101
 
101
- YYYY_HYPHEN_YYYY_REGEX = Regexp.new(/(?<first>\d{3,4})\??\s*(-|—|–|to)\s*(?<last>\d{4})\??/m)
102
+ YYYY_HYPHEN_YYYY_REGEX = Regexp.new(/(?<first>\d{3,4})s?\??\s*(-|—|–|to)\s*(?<last>\d{4}s?)\??/m)
102
103
 
103
104
  # Integer value for latest year if we have "yyyy-yyyy" pattern
104
105
  # @return [Integer, nil] yyyy if date_str matches pattern; nil otherwise
@@ -109,7 +110,13 @@ class ParseDate
109
110
  # Integer value for latest year if we have "yyyy-yyyy" pattern
110
111
  # @return [Integer, nil] yyyy if date_str matches pattern; nil otherwise
111
112
  def hyphen_4digit_latest_year(date_str)
112
- Regexp.last_match(:last).to_i if date_str.match(YYYY_HYPHEN_YYYY_REGEX)
113
+ latest = Regexp.last_match(:last) if date_str.match(YYYY_HYPHEN_YYYY_REGEX)
114
+ if ParseDate.year_int_valid?(latest.to_i)
115
+ ParseDate.latest_year(latest) # accommodates '1980s - 1990s'
116
+ else
117
+ # return the bad value; parse_range might need to complain about it
118
+ latest
119
+ end
113
120
  end
114
121
 
115
122
  YYYY_HYPHEN_YY_REGEX = Regexp.new(/(?<first>\d{3,4})\??\s*(-|—|–|to)\s*(?<last>\d{2})\??([^-0-9].*)?$/)
@@ -219,6 +226,16 @@ class ParseDate
219
226
  nil # explicitly want nil if date won't parse
220
227
  end
221
228
 
229
+ DECADE_0S_REGEX = Regexp.new('(^|\D)\d{3}0\'?s($|\D)', REGEX_OPTS)
230
+
231
+ # last year of decade (as String) if we have: yyy0s flavor pattern
232
+ # @return [String, nil] 4 digit year (e.g. 1869, 1959) if date_str matches pattern, nil otherwise
233
+ def last_year_for_0s_decade(date_str)
234
+ decade_matches = date_str.match(DECADE_0S_REGEX)
235
+ changed_to_nine = decade_matches.to_s.sub(/0\'?s/, '9') if decade_matches
236
+ ParseDate.first_four_digits(changed_to_nine) if changed_to_nine
237
+ end
238
+
222
239
  DECADE_4CHAR_REGEX = Regexp.new('(^|\D)\d{3}[u\-?x]($|\D)', REGEX_OPTS)
223
240
 
224
241
  # first year of decade (as String) if we have: yyyu, yyy-, yyy? or yyyx pattern
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ParseDate
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
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.4.0
4
+ version: 0.4.1
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-11-01 00:00:00.000000000 Z
11
+ date: 2019-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk