american_date 1.2.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fd9a4c53baa027ff94f1802a0f51e78bdc68fc9892d49152072b8eb2205f671
4
- data.tar.gz: d56ba6c7c8a88eeb79a2993fac0c3eb69c2318437a3299eaf087e94213720ce1
3
+ metadata.gz: 7ad1d14cdbbdd03f5c6eef433b17dbb9e5bd296a1a244ce25cf2dec846ef5f4c
4
+ data.tar.gz: 66ca9d13ae079e149a3b2d7228b62cacde0a9b722f28450caf50bd0910c778e8
5
5
  SHA512:
6
- metadata.gz: dfd6235350c26f3ed600bdcc5a6497cb9633666bda0df00c7129d142f145edd8fe6e14a8e9aa8b82398abf3210141e50d09a4c2c12021da69183cd3a691282cf
7
- data.tar.gz: dc035e0b03255603061bd2a419250ab05c57187c60b441b64afe0de3a2730f620e594c46f7a7c7a2b67dfdbc3025c2c9583a2c840306a8db95e98793454461a5
6
+ metadata.gz: 1bd9aab61e47d7fc2ad2a1ca41181fbda894675d9afcfe718cf9c2de55663b6901b5cb7655392084b6479e9968c3423a0308895d1dfc1e1f7c5cfb392a8ab53e
7
+ data.tar.gz: c8a4d9579fc57d4cac21142d6cd7a5e36f44b05642fa5d5e9ea3b0907523b03199bc66d1193b4f10187848ab5dbbb02e24869d357a539e976acd71fe7057b45c
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.3.0 (2023-07-13)
2
+
3
+ * Make sure AMERICAN_DATE_RE constant is defined on Date and not on the top level (jeremyevans)
4
+
1
5
  === 1.2.0 (2021-11-17)
2
6
 
3
7
  * Support the limit keyword argument supported by date 3.2.1+ (jeremyevans)
data/lib/american_date.rb CHANGED
@@ -1,22 +1,27 @@
1
1
  require 'date'
2
2
 
3
+ # :nocov:
3
4
  if RUBY_VERSION >= '1.9'
5
+ # :nocov:
4
6
  long_date = ' ' * 128 + '2021-10-11'
5
7
  limit_supported = begin
6
8
  Date.parse(long_date)
7
9
  rescue ArgumentError
8
10
  (Date.parse(long_date, true, Date::ITALY, :limit=>nil) == Date.new(2021, 10, 11)) rescue false
11
+ # :nocov:
9
12
  else
10
13
  false
14
+ # :nocov:
11
15
  end
12
16
 
17
+ # American date format detected by the library.
18
+ Date::AMERICAN_DATE_RE = eval('%r_(?<!\d)(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})(?!\d)_').freeze
19
+ # Negative lookbehinds, which are not supported in Ruby 1.8
20
+ # so by using eval, we prevent an error when this file is first parsed
21
+ # since the regexp itself will only be parsed at runtime if the RUBY_VERSION condition is met.
22
+
13
23
  # Modify parsing methods to handle american date format correctly.
14
24
  Date.instance_eval do
15
- # American date format detected by the library.
16
- AMERICAN_DATE_RE = eval('%r_(?<!\d)(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})(?!\d)_').freeze
17
- # Negative lookbehinds, which are not supported in Ruby 1.8
18
- # so by using eval, we prevent an error when this file is first parsed
19
- # since the regexp itself will only be parsed at runtime if the RUBY_VERSION condition is met.
20
25
 
21
26
  # Alias for stdlib Date._parse
22
27
  alias _parse_without_american_date _parse
@@ -27,14 +32,18 @@ if RUBY_VERSION >= '1.9'
27
32
  _parse_without_american_date(convert_american_to_iso(string), comp, limit: limit)
28
33
  end
29
34
  END
35
+ # :nocov:
30
36
  else
31
37
  # Transform american dates into ISO dates before parsing.
32
38
  def _parse(string, comp=true)
33
39
  _parse_without_american_date(convert_american_to_iso(string), comp)
34
40
  end
41
+ # :nocov:
35
42
  end
36
43
 
44
+ # :nocov:
37
45
  if RUBY_VERSION >= '1.9.3'
46
+ # :nocov:
38
47
  # Alias for stdlib Date.parse
39
48
  alias parse_without_american_date parse
40
49
 
@@ -44,12 +53,14 @@ if RUBY_VERSION >= '1.9'
44
53
  parse_without_american_date(convert_american_to_iso(string), comp, start, limit: limit)
45
54
  end
46
55
  END
56
+ # :nocov:
47
57
  else
48
58
  # Transform american dates into ISO dates before parsing.
49
59
  def parse(string, comp=true, start=Date::ITALY)
50
60
  parse_without_american_date(convert_american_to_iso(string), comp, start)
51
61
  end
52
62
  end
63
+ # :nocov:
53
64
  end
54
65
 
55
66
  private
@@ -67,11 +78,13 @@ if RUBY_VERSION >= '1.9'
67
78
  raise TypeError, "no implicit conversion of #{string.inspect} into String"
68
79
  end
69
80
  end
70
- string.sub(AMERICAN_DATE_RE){|m| "#$3-#$1-#$2"}
81
+ string.sub(Date::AMERICAN_DATE_RE){|m| "#$3-#$1-#$2"}
71
82
  end
72
83
  end
73
84
 
85
+ # :nocov:
74
86
  if RUBY_VERSION >= '1.9.3'
87
+ # :nocov:
75
88
  # Modify parsing methods to handle american date format correctly.
76
89
  DateTime.instance_eval do
77
90
  # Alias for stdlib Date.parse
@@ -83,12 +96,14 @@ if RUBY_VERSION >= '1.9'
83
96
  parse_without_american_date(convert_american_to_iso(string), comp, start, limit: limit)
84
97
  end
85
98
  END
99
+ # :nocov:
86
100
  else
87
101
  # Transform american dates into ISO dates before parsing.
88
102
  def parse(string, comp=true, start=Date::ITALY)
89
103
  parse_without_american_date(convert_american_to_iso(string), comp, start)
90
104
  end
91
105
  end
106
+ # :nocov:
92
107
  end
93
108
  end
94
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: american_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-17 00:00:00.000000000 Z
11
+ date: 2023-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -50,10 +50,7 @@ files:
50
50
  - CHANGELOG
51
51
  - MIT-LICENSE
52
52
  - README.rdoc
53
- - Rakefile
54
53
  - lib/american_date.rb
55
- - spec/american_date_keyword_spec.rb
56
- - spec/american_date_spec.rb
57
54
  homepage: https://github.com/jeremyevans/ruby-american_date
58
55
  licenses:
59
56
  - MIT
@@ -61,7 +58,7 @@ metadata:
61
58
  bug_tracker_uri: https://github.com/jeremyevans/ruby-american_date/issues
62
59
  changelog_uri: https://github.com/jeremyevans/ruby-american_date/blob/master/CHANGELOG
63
60
  source_code_uri: https://github.com/jeremyevans/ruby-american_date
64
- post_install_message:
61
+ post_install_message:
65
62
  rdoc_options:
66
63
  - "--quiet"
67
64
  - "--inline-source"
@@ -83,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
80
  - !ruby/object:Gem::Version
84
81
  version: '0'
85
82
  requirements: []
86
- rubygems_version: 3.2.22
87
- signing_key:
83
+ rubygems_version: 3.4.10
84
+ signing_key:
88
85
  specification_version: 4
89
86
  summary: American style month/day/year date parsing for ruby 1.9+
90
87
  test_files: []
data/Rakefile DELETED
@@ -1,37 +0,0 @@
1
- require "rake"
2
- require "rake/clean"
3
-
4
- CLEAN.include ["*.gem", "rdoc"]
5
- RDOC_OPTS = ['--inline-source', '--line-numbers', '--title', '', '--main', 'README.rdoc']
6
-
7
- rdoc_task_class = begin
8
- require "rdoc/task"
9
- RDOC_OPTS.concat(['-f', 'hanna'])
10
- RDoc::Task
11
- rescue LoadError
12
- begin
13
- require "rake/rdoctask"
14
- Rake::RDocTask
15
- rescue RuntimeError
16
- end
17
- end
18
-
19
- if rdoc_task_class
20
- rdoc_task_class.new do |rdoc|
21
- rdoc.rdoc_dir = "rdoc"
22
- rdoc.options += RDOC_OPTS
23
- rdoc.rdoc_files.add %w"lib/american_date.rb MIT-LICENSE CHANGELOG README.rdoc"
24
- end
25
- end
26
-
27
- desc "Run specs"
28
- task :spec do
29
- sh "#{FileUtils::RUBY} -I lib spec/american_date_spec.rb"
30
- end
31
- task :default=>[:spec]
32
-
33
- desc "Package american_date"
34
- task :gem=>[:clean] do
35
- load './american_date.gemspec'
36
- Gem::Builder.new(AMERICAN_DATE_GEMSPEC).build
37
- end
@@ -1,40 +0,0 @@
1
- long_date = ' ' * 128 + '01/02/2003'
2
- limit_supported = begin
3
- Date.parse(long_date)
4
- rescue ArgumentError
5
- if ((Date.parse(long_date, true, Date::ITALY, :limit=>nil) == Date.new(2003, 1, 2)) rescue false)
6
- describe "Date.parse" do
7
- specify "should not support long dates without limit keyword" do
8
- proc{Date.parse(long_date, true)}.must_raise ArgumentError
9
- end
10
-
11
- specify "should not support long dates with limit keyword" do
12
- Date.parse(long_date, true, limit: 150).must_equal Date.new(2003, 1, 2)
13
- Date.parse(long_date, true, limit: nil).must_equal Date.new(2003, 1, 2)
14
- end
15
- end
16
-
17
- describe "DateTime.parse" do
18
- long_datetime = long_date + ' 10:11:12'
19
- specify "should not support long dates without limit keyword" do
20
- proc{DateTime.parse(long_datetime, true)}.must_raise ArgumentError
21
- end
22
-
23
- specify "should not support long dates with limit keyword" do
24
- DateTime.parse(long_datetime, true, limit: 150).must_equal DateTime.new(2003, 1, 2, 10, 11, 12)
25
- DateTime.parse(long_datetime, true, limit: nil).must_equal DateTime.new(2003, 1, 2, 10, 11, 12)
26
- end
27
- end
28
-
29
- describe "Date._parse" do
30
- specify "should not support long dates without limit keyword" do
31
- proc{Date._parse(long_date, true)}.must_raise ArgumentError
32
- end
33
-
34
- specify "should not support long dates with limit keyword" do
35
- Date._parse(long_date, true, limit: 150).must_equal(:year=>2003, :mon=>1, :mday=>2)
36
- Date._parse(long_date, true, limit: nil).must_equal(:year=>2003, :mon=>1, :mday=>2)
37
- end
38
- end
39
- end
40
- end
@@ -1,269 +0,0 @@
1
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib', 'american_date')
2
- require 'time'
3
- require 'rubygems'
4
- ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
5
- gem 'minitest'
6
- require 'minitest/global_expectations/autorun'
7
-
8
- if RUBY_VERSION >= '2.0'
9
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'spec', 'american_date_keyword_spec')
10
- end
11
-
12
- describe "Date.parse" do
13
- specify "should use american date format for dd/mm/yy" do
14
- Date.parse('01/02/03', true).must_equal Date.new(2003, 1, 2)
15
- Date.parse('01/02/03', true, Date::ITALY).must_equal Date.new(2003, 1, 2)
16
- end
17
-
18
- specify "should use american date format for d/m/yy" do
19
- Date.parse('1/2/03', true).must_equal Date.new(2003, 1, 2)
20
- Date.parse('1/2/03', false).must_equal Date.new(3, 1, 2)
21
- end
22
-
23
- specify "should use american date format for dd/mm/yyyy" do
24
- Date.parse('01/02/2003').must_equal Date.new(2003, 1, 2)
25
- end
26
-
27
- specify "should use american date format for dd/mm" do
28
- Date.parse('01/02').must_equal Date.new(Time.now.year, 1, 2)
29
- end
30
-
31
- specify "should use american date format for d/m" do
32
- Date.parse('1/2').must_equal Date.new(Time.now.year, 1, 2)
33
- end
34
-
35
- specify "should ignore preceding whitespace" do
36
- Date.parse(' 01/02/2003').must_equal Date.new(2003, 1, 2)
37
- end
38
-
39
- specify "should ignore preceding weekday" do
40
- Date.parse('Day 01/02/2003').must_equal Date.new(2003, 1, 2)
41
- end
42
-
43
- specify "should work just like 1.8 does" do
44
- Date.parse('10:20:30something01/02/2003else').must_equal Date.new(2003, 1, 2)
45
- end
46
-
47
- specify "should not mismatch years" do
48
- Date.parse('2003/01/02').must_equal Date.new(2003, 1, 2)
49
- end
50
-
51
- specify "should behave like 1.8 and only allow / as delimiters in american-style dates" do
52
- Date.parse("10/11/2012").must_equal Date.new(2012, 10, 11)
53
- Date.parse("10-11-2012").must_equal Date.new(2012, 11, 10)
54
- Date.parse("10.11.2012").must_equal Date.new(2012, 11, 10)
55
- end
56
-
57
- if RUBY_VERSION > '1.9'
58
- specify "should raise TypeError for invalid values" do
59
- [nil, 1, 1.0, [], {}].each do |x|
60
- proc{Date.parse(x)}.must_raise(TypeError)
61
- end
62
- end
63
-
64
- specify "should handle values implicitly convertible to String" do
65
- o = Object.new
66
- def o.to_str() '01/02/2003' end
67
- Date.parse(o).must_equal Date.new(2003, 1, 2)
68
- end
69
-
70
- specify "should handle values implicitly convertible to String" do
71
- o = Object.new
72
- def o.to_str() 1 end
73
- proc{Date.parse(o)}.must_raise(TypeError)
74
- end
75
- end
76
- end
77
-
78
- describe "DateTime.parse" do
79
- specify "should use american date format for dd/mm/yy" do
80
- DateTime.parse('01/02/03', true).must_equal DateTime.new(2003, 1, 2)
81
- DateTime.parse('01/02/03', true, DateTime::ITALY).must_equal DateTime.new(2003, 1, 2)
82
- end
83
-
84
- specify "should use american date format for d/m/yy" do
85
- DateTime.parse('1/2/03', true).must_equal DateTime.new(2003, 1, 2)
86
- DateTime.parse('1/2/03', false).must_equal DateTime.new(3, 1, 2)
87
- end
88
-
89
- specify "should use american date format for dd/mm/yyyy" do
90
- DateTime.parse('01/02/2003').must_equal DateTime.new(2003, 1, 2)
91
- end
92
-
93
- specify "should use american date format for dd/mm" do
94
- DateTime.parse('01/02').must_equal DateTime.new(Time.now.year, 1, 2)
95
- end
96
-
97
- specify "should use american date format for d/m" do
98
- DateTime.parse('1/2').must_equal DateTime.new(Time.now.year, 1, 2)
99
- end
100
-
101
- specify "should ignore preceding whitespace" do
102
- DateTime.parse(' 01/02/2003').must_equal DateTime.new(2003, 1, 2)
103
- end
104
-
105
- specify "should ignore preceding weekday" do
106
- DateTime.parse('Day 01/02/2003').must_equal Date.new(2003, 1, 2)
107
- end
108
-
109
- specify "should work with times" do
110
- DateTime.parse('01/02/2003 10:20:30').must_equal DateTime.new(2003, 1, 2, 10, 20, 30)
111
- end
112
-
113
- specify "should work with times and weekdays" do
114
- DateTime.parse('Day 01/02/2003 10:20:30').must_equal DateTime.new(2003, 1, 2, 10, 20, 30)
115
- end
116
-
117
- specify "should work just like 1.8 does" do
118
- DateTime.parse('10:20:30something01/02/2003else').must_equal DateTime.new(2003, 1, 2, 10, 20, 30)
119
- end
120
-
121
- specify "should not mismatch years" do
122
- DateTime.parse('2003/01/02').must_equal Date.new(2003, 1, 2)
123
- end
124
-
125
- if RUBY_VERSION > '1.9'
126
- specify "should raise TypeError for invalid values" do
127
- [nil, 1, 1.0, [], {}].each do |x|
128
- proc{DateTime.parse(x)}.must_raise(TypeError)
129
- end
130
- end
131
-
132
- specify "should handle values implicitly convertible to String" do
133
- o = Object.new
134
- def o.to_str() '01/02/2003' end
135
- DateTime.parse(o).must_equal DateTime.new(2003, 1, 2)
136
- end
137
-
138
- specify "should handle values implicitly convertible to String" do
139
- o = Object.new
140
- def o.to_str() 1 end
141
- proc{DateTime.parse(o)}.must_raise(TypeError)
142
- end
143
- end
144
- end
145
-
146
- describe "Time.parse" do
147
- specify "should use american date format for dd/mm/yy" do
148
- Time.parse('01/02/03').must_equal Time.local(2003, 1, 2)
149
- end
150
-
151
- specify "should use american date format for d/m/yy" do
152
- Time.parse('1/2/03').must_equal Time.local(2003, 1, 2)
153
- end
154
-
155
- specify "should use american date format for dd/mm/yyyy" do
156
- Time.parse('01/02/2003').must_equal Time.local(2003, 1, 2)
157
- end
158
-
159
- specify "should use american date format for dd/mm" do
160
- Time.parse('01/02').must_equal Time.local(Time.now.year, 1, 2)
161
- end
162
-
163
- specify "should use american date format for d/m" do
164
- Time.parse('1/2').must_equal Time.local(Time.now.year, 1, 2)
165
- end
166
-
167
- specify "should ignore preceding whitespace" do
168
- Time.parse(' 01/02/2003').must_equal Time.local(2003, 1, 2)
169
- end
170
-
171
- specify "should ignore preceding weekdays" do
172
- Time.parse('Day 01/02/2003').must_equal Time.local(2003, 1, 2)
173
- end
174
-
175
- specify "should work with times" do
176
- Time.parse('01/02/2003 10:20:30').must_equal Time.local(2003, 1, 2, 10, 20, 30)
177
- end
178
-
179
- specify "should work with times and weekdays" do
180
- Time.parse('Day 01/02/2003 10:20:30').must_equal Time.local(2003, 1, 2, 10, 20, 30)
181
- end
182
-
183
- specify "should work with time first and date second" do
184
- Time.parse('10:20:30 01/02/2003').must_equal Time.local(2003, 1, 2, 10, 20, 30)
185
- end
186
-
187
- specify "should work with time first and date second and weekday in the middle" do
188
- Time.parse('10:20:30 Thu 01/02/2003').must_equal Time.local(2003, 1, 2, 10, 20, 30)
189
- end
190
-
191
- specify "should work just like 1.8 does" do
192
- Time.parse('10:20:30something01/02/2003else').must_equal Time.local(2003, 1, 2, 10, 20, 30)
193
- end
194
-
195
- specify "should not mismatch years" do
196
- Time.parse('2003/01/02').must_equal Time.local(2003, 1, 2, 0, 0, 0)
197
- end
198
-
199
- if RUBY_VERSION > '1.9'
200
- specify "should raise TypeError for invalid values" do
201
- [nil, 1, 1.0, [], {}].each do |x|
202
- proc{Time.parse(x)}.must_raise(TypeError)
203
- end
204
- end
205
-
206
- specify "should handle values implicitly convertible to String" do
207
- o = Object.new
208
- def o.to_str() '01/02/2003' end
209
- Time.parse(o).must_equal Time.local(2003, 1, 2)
210
- end
211
-
212
- specify "should handle values implicitly convertible to String" do
213
- o = Object.new
214
- def o.to_str() 1 end
215
- proc{Time.parse(o)}.must_raise(TypeError)
216
- end
217
- end
218
- end
219
-
220
- describe "Date._parse" do
221
- specify "should use american date format for dd/mm/yy" do
222
- Date._parse('01/02/03', true).must_equal(:year=>2003, :mon=>1, :mday=>2)
223
- end
224
-
225
- specify "should use american date format for d/m/yy" do
226
- Date._parse('1/2/03', true).must_equal(:year=>2003, :mon=>1, :mday=>2)
227
- Date._parse('1/2/03', false).must_equal(:year=>3, :mon=>1, :mday=>2)
228
- end
229
-
230
- specify "should use american date format for dd/mm/yyyy" do
231
- Date._parse('01/02/2003').must_equal(:year=>2003, :mon=>1, :mday=>2)
232
- end
233
-
234
- specify "should use american date format for dd/mm" do
235
- Date._parse('01/02').must_equal(:mon=>1, :mday=>2)
236
- end
237
-
238
- specify "should use american date format for d/m" do
239
- Date._parse('1/2').must_equal(:mon=>1, :mday=>2)
240
- end
241
-
242
- specify "should ignore preceding whitespace" do
243
- Date._parse(' 01/02/2003').must_equal(:year=>2003, :mon=>1, :mday=>2)
244
- end
245
-
246
- specify "should work with times" do
247
- DateTime._parse('01/02/2003 10:20:30').must_equal(:year=>2003, :mon=>1, :mday=>2, :hour=>10, :min=>20, :sec=>30)
248
- end
249
-
250
- if RUBY_VERSION > '1.9'
251
- specify "should raise TypeError for invalid values" do
252
- [nil, 1, 1.0, [], {}].each do |x|
253
- proc{DateTime._parse(x)}.must_raise(TypeError)
254
- end
255
- end
256
-
257
- specify "should handle values implicitly convertible to String" do
258
- o = Object.new
259
- def o.to_str() '01/02/2003' end
260
- DateTime._parse(o).must_equal(:year=>2003, :mon=>1, :mday=>2)
261
- end
262
-
263
- specify "should handle values implicitly convertible to String" do
264
- o = Object.new
265
- def o.to_str() 1 end
266
- proc{DateTime._parse(o)}.must_raise(TypeError)
267
- end
268
- end
269
- end