american_date 1.0.0 → 1.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2fd9a4c53baa027ff94f1802a0f51e78bdc68fc9892d49152072b8eb2205f671
4
+ data.tar.gz: d56ba6c7c8a88eeb79a2993fac0c3eb69c2318437a3299eaf087e94213720ce1
5
+ SHA512:
6
+ metadata.gz: dfd6235350c26f3ed600bdcc5a6497cb9633666bda0df00c7129d142f145edd8fe6e14a8e9aa8b82398abf3210141e50d09a4c2c12021da69183cd3a691282cf
7
+ data.tar.gz: dc035e0b03255603061bd2a419250ab05c57187c60b441b64afe0de3a2730f620e594c46f7a7c7a2b67dfdbc3025c2c9583a2c840306a8db95e98793454461a5
data/CHANGELOG CHANGED
@@ -1,3 +1,21 @@
1
+ === 1.2.0 (2021-11-17)
2
+
3
+ * Support the limit keyword argument supported by date 3.2.1+ (jeremyevans)
4
+
5
+ === 1.1.1 (2015-10-27)
6
+
7
+ * Support the third argument to Date/DateTime.parse (costi) (#13)
8
+
9
+ === 1.1.0 (2013-03-23)
10
+
11
+ * Handle MM/DD/YYYY substrings in the middle of strings, not just the beginning (sd, clonezone, jeremyevans) (#5)
12
+
13
+ === 1.0.1 (2013-03-20)
14
+
15
+ * Don't freeze the regular expression used, to allow easier overrides (jeremyevans)
16
+
17
+ * Raise TypeError if passed object not implicitly convertible to String (jeremyevans) (#6)
18
+
1
19
  === 1.0.0 (2011-12-12)
2
20
 
3
21
  * Initial public release
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Jeremy Evans
1
+ Copyright (c) 2011-2021 Jeremy Evans
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to
data/README.rdoc CHANGED
@@ -1,9 +1,9 @@
1
1
  = ruby-american_date
2
2
 
3
- ruby-american_date exists to make ruby versions greater than 1.8
4
- parse american-style month/day/year dates correctly, just like
5
- ruby 1.8. It can also be used on ruby 1.8, but it is basically a
6
- noop there.
3
+ ruby-american_date exists to make ruby 1.9+ parse american-style
4
+ month/day/year dates correctly, with behavior matching ruby 1.8.7.
5
+ It can also be used on earlier ruby versions, but it is basically
6
+ a noop there.
7
7
 
8
8
  As far as I know, there isn't a gem that already handles this. You
9
9
  can find many snippets on the web that partially solve the issue, but
@@ -12,28 +12,21 @@ DateTime.parse no longer call Date._parse directly on 1.9.3. Also
12
12
  most don't handle cases where an american date format is used in
13
13
  addition to a time format.
14
14
 
15
- == Design
16
-
17
- The general idea is fairly simple. We just check the beginning of
18
- the input string for an american date format, and transform it into
19
- a year-month-day ISO format before passing it to the standard date
20
- parsing methods. This is probably the least invasive way that works
21
- correctly on both the pure-ruby date parser (<1.9.3) and the C
22
- extension date parser (>=1.9.3).
23
-
24
- To reduce the possibility of problems, only the beginning of the
25
- input string is checked. So if you have an american date format
26
- embedded in the middle of the input string, it won't be translated.
27
- That may change in the future if it is determined to be safe.
15
+ Note that this gem only handles / separated dates. It does not
16
+ handle - or . separated dates. This is by design, for compatibility
17
+ with ruby 1.8.7.
28
18
 
29
- == Tested ruby versions
19
+ == Design
30
20
 
31
- * ruby 1.8.6, 1.8.7, 1.9.2, 1.9.3
32
- * rubinius 1.2.4
33
- * jruby 1.6.5 (both --1.8 and --1.9 modes)
21
+ The general idea is fairly simple. We look for a month/day/year
22
+ substring in the input string, and if we find it, we transform it
23
+ into a year-month-day ISO format string before passing it to the
24
+ standard date parsing methods. This is probably the least invasive
25
+ way that works correctly on both the pure-ruby date parser (<1.9.3)
26
+ and the C extension date parser (>=1.9.3).
34
27
 
35
28
  == Installation
36
-
29
+
37
30
  ruby-american_date is distributed as a gem, and can be installed with:
38
31
 
39
32
  gem install american_date
data/Rakefile CHANGED
@@ -9,30 +9,24 @@ rdoc_task_class = begin
9
9
  RDOC_OPTS.concat(['-f', 'hanna'])
10
10
  RDoc::Task
11
11
  rescue LoadError
12
- require "rake/rdoctask"
13
- Rake::RDocTask
12
+ begin
13
+ require "rake/rdoctask"
14
+ Rake::RDocTask
15
+ rescue RuntimeError
16
+ end
14
17
  end
15
18
 
16
- rdoc_task_class.new do |rdoc|
17
- rdoc.rdoc_dir = "rdoc"
18
- rdoc.options += RDOC_OPTS
19
- rdoc.rdoc_files.add %w"lib/american_date.rb MIT-LICENSE CHANGELOG README.rdoc"
20
- end
21
-
22
- begin
23
- require "spec/rake/spectask"
24
- spec_class = Spec::Rake::SpecTask
25
- spec_files_meth = :spec_files=
26
- rescue LoadError
27
- # RSpec 2
28
- require "rspec/core/rake_task"
29
- spec_class = RSpec::Core::RakeTask
30
- spec_files_meth = :pattern=
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
31
25
  end
32
26
 
33
27
  desc "Run specs"
34
- spec_class.new("spec") do |t|
35
- t.send(spec_files_meth, ["spec/american_date_spec.rb"])
28
+ task :spec do
29
+ sh "#{FileUtils::RUBY} -I lib spec/american_date_spec.rb"
36
30
  end
37
31
  task :default=>[:spec]
38
32
 
data/lib/american_date.rb CHANGED
@@ -1,26 +1,54 @@
1
1
  require 'date'
2
2
 
3
3
  if RUBY_VERSION >= '1.9'
4
+ long_date = ' ' * 128 + '2021-10-11'
5
+ limit_supported = begin
6
+ Date.parse(long_date)
7
+ rescue ArgumentError
8
+ (Date.parse(long_date, true, Date::ITALY, :limit=>nil) == Date.new(2021, 10, 11)) rescue false
9
+ else
10
+ false
11
+ end
12
+
4
13
  # Modify parsing methods to handle american date format correctly.
5
- class << Date
14
+ Date.instance_eval do
6
15
  # American date format detected by the library.
7
- AMERICAN_DATE_RE = %r_\A\s*(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})_.freeze
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.
8
20
 
9
21
  # Alias for stdlib Date._parse
10
22
  alias _parse_without_american_date _parse
11
23
 
12
- # Transform american dates into ISO dates before parsing.
13
- def _parse(string, comp=true)
14
- _parse_without_american_date(convert_american_to_iso(string), comp)
24
+ if limit_supported
25
+ instance_eval(<<-END, __FILE__, __LINE__+1)
26
+ def _parse(string, comp=true, limit: 128)
27
+ _parse_without_american_date(convert_american_to_iso(string), comp, limit: limit)
28
+ end
29
+ END
30
+ else
31
+ # Transform american dates into ISO dates before parsing.
32
+ def _parse(string, comp=true)
33
+ _parse_without_american_date(convert_american_to_iso(string), comp)
34
+ end
15
35
  end
16
36
 
17
37
  if RUBY_VERSION >= '1.9.3'
18
38
  # Alias for stdlib Date.parse
19
39
  alias parse_without_american_date parse
20
40
 
21
- # Transform american dates into ISO dates before parsing.
22
- def parse(string, comp=true)
23
- parse_without_american_date(convert_american_to_iso(string), comp)
41
+ if limit_supported
42
+ instance_eval(<<-END, __FILE__, __LINE__+1)
43
+ def parse(string, comp=true, start=Date::ITALY, limit: 128)
44
+ parse_without_american_date(convert_american_to_iso(string), comp, start, limit: limit)
45
+ end
46
+ END
47
+ else
48
+ # Transform american dates into ISO dates before parsing.
49
+ def parse(string, comp=true, start=Date::ITALY)
50
+ parse_without_american_date(convert_american_to_iso(string), comp, start)
51
+ end
24
52
  end
25
53
  end
26
54
 
@@ -28,19 +56,38 @@ if RUBY_VERSION >= '1.9'
28
56
 
29
57
  # Transform american date fromat into ISO format.
30
58
  def convert_american_to_iso(string)
59
+ unless string.is_a?(String)
60
+ if string.respond_to?(:to_str)
61
+ str = string.to_str
62
+ unless str.is_a?(String)
63
+ raise TypeError, "no implicit conversion of #{string.inspect} into String"
64
+ end
65
+ string = str
66
+ else
67
+ raise TypeError, "no implicit conversion of #{string.inspect} into String"
68
+ end
69
+ end
31
70
  string.sub(AMERICAN_DATE_RE){|m| "#$3-#$1-#$2"}
32
71
  end
33
72
  end
34
73
 
35
74
  if RUBY_VERSION >= '1.9.3'
36
75
  # Modify parsing methods to handle american date format correctly.
37
- class << DateTime
76
+ DateTime.instance_eval do
38
77
  # Alias for stdlib Date.parse
39
78
  alias parse_without_american_date parse
40
79
 
41
- # Transform american dates into ISO dates before parsing.
42
- def parse(string, comp=true)
43
- parse_without_american_date(convert_american_to_iso(string), comp)
80
+ if limit_supported
81
+ instance_eval(<<-END, __FILE__, __LINE__+1)
82
+ def parse(string, comp=true, start=Date::ITALY, limit: 128)
83
+ parse_without_american_date(convert_american_to_iso(string), comp, start, limit: limit)
84
+ end
85
+ END
86
+ else
87
+ # Transform american dates into ISO dates before parsing.
88
+ def parse(string, comp=true, start=Date::ITALY)
89
+ parse_without_american_date(convert_american_to_iso(string), comp, start)
90
+ end
44
91
  end
45
92
  end
46
93
  end
@@ -0,0 +1,40 @@
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,121 +1,269 @@
1
1
  require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib', 'american_date')
2
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
3
11
 
4
12
  describe "Date.parse" do
5
13
  specify "should use american date format for dd/mm/yy" do
6
- Date.parse('01/02/03', true).should == Date.new(2003, 1, 2)
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)
7
16
  end
8
17
 
9
18
  specify "should use american date format for d/m/yy" do
10
- Date.parse('1/2/03', true).should == Date.new(2003, 1, 2)
11
- Date.parse('1/2/03', false).should == Date.new(3, 1, 2)
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)
12
21
  end
13
22
 
14
23
  specify "should use american date format for dd/mm/yyyy" do
15
- Date.parse('01/02/2003').should == Date.new(2003, 1, 2)
24
+ Date.parse('01/02/2003').must_equal Date.new(2003, 1, 2)
16
25
  end
17
26
 
18
27
  specify "should use american date format for dd/mm" do
19
- Date.parse('01/02').should == Date.new(Time.now.year, 1, 2)
28
+ Date.parse('01/02').must_equal Date.new(Time.now.year, 1, 2)
20
29
  end
21
30
 
22
31
  specify "should use american date format for d/m" do
23
- Date.parse('1/2').should == Date.new(Time.now.year, 1, 2)
32
+ Date.parse('1/2').must_equal Date.new(Time.now.year, 1, 2)
24
33
  end
25
34
 
26
35
  specify "should ignore preceding whitespace" do
27
- Date.parse(' 01/02/2003').should == Date.new(2003, 1, 2)
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
28
75
  end
29
76
  end
30
77
 
31
78
  describe "DateTime.parse" do
32
79
  specify "should use american date format for dd/mm/yy" do
33
- DateTime.parse('01/02/03', true).should == DateTime.new(2003, 1, 2)
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)
34
82
  end
35
83
 
36
84
  specify "should use american date format for d/m/yy" do
37
- DateTime.parse('1/2/03', true).should == DateTime.new(2003, 1, 2)
38
- DateTime.parse('1/2/03', false).should == DateTime.new(3, 1, 2)
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)
39
87
  end
40
88
 
41
89
  specify "should use american date format for dd/mm/yyyy" do
42
- DateTime.parse('01/02/2003').should == DateTime.new(2003, 1, 2)
90
+ DateTime.parse('01/02/2003').must_equal DateTime.new(2003, 1, 2)
43
91
  end
44
92
 
45
93
  specify "should use american date format for dd/mm" do
46
- DateTime.parse('01/02').should == DateTime.new(Time.now.year, 1, 2)
94
+ DateTime.parse('01/02').must_equal DateTime.new(Time.now.year, 1, 2)
47
95
  end
48
96
 
49
97
  specify "should use american date format for d/m" do
50
- DateTime.parse('1/2').should == DateTime.new(Time.now.year, 1, 2)
98
+ DateTime.parse('1/2').must_equal DateTime.new(Time.now.year, 1, 2)
51
99
  end
52
100
 
53
101
  specify "should ignore preceding whitespace" do
54
- DateTime.parse(' 01/02/2003').should == DateTime.new(2003, 1, 2)
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)
55
107
  end
56
108
 
57
109
  specify "should work with times" do
58
- DateTime.parse('01/02/2003 10:20:30').should == DateTime.new(2003, 1, 2, 10, 20, 30)
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
59
143
  end
60
144
  end
61
145
 
62
146
  describe "Time.parse" do
63
147
  specify "should use american date format for dd/mm/yy" do
64
- Time.parse('01/02/03', true).should == Time.local(2003, 1, 2)
148
+ Time.parse('01/02/03').must_equal Time.local(2003, 1, 2)
65
149
  end
66
150
 
67
151
  specify "should use american date format for d/m/yy" do
68
- Time.parse('1/2/03', true).should == Time.local(2003, 1, 2)
152
+ Time.parse('1/2/03').must_equal Time.local(2003, 1, 2)
69
153
  end
70
154
 
71
155
  specify "should use american date format for dd/mm/yyyy" do
72
- Time.parse('01/02/2003').should == Time.local(2003, 1, 2)
156
+ Time.parse('01/02/2003').must_equal Time.local(2003, 1, 2)
73
157
  end
74
158
 
75
159
  specify "should use american date format for dd/mm" do
76
- Time.parse('01/02').should == Time.local(Time.now.year, 1, 2)
160
+ Time.parse('01/02').must_equal Time.local(Time.now.year, 1, 2)
77
161
  end
78
162
 
79
163
  specify "should use american date format for d/m" do
80
- Time.parse('1/2').should == Time.local(Time.now.year, 1, 2)
164
+ Time.parse('1/2').must_equal Time.local(Time.now.year, 1, 2)
81
165
  end
82
166
 
83
167
  specify "should ignore preceding whitespace" do
84
- Time.parse(' 01/02/2003').should == Time.local(2003, 1, 2)
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)
85
173
  end
86
174
 
87
175
  specify "should work with times" do
88
- Time.parse('01/02/2003 10:20:30').should == Time.local(2003, 1, 2, 10, 20, 30)
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
89
217
  end
90
218
  end
91
219
 
92
220
  describe "Date._parse" do
93
221
  specify "should use american date format for dd/mm/yy" do
94
- Date._parse('01/02/03', true).should == {:year=>2003, :mon=>1, :mday=>2}
222
+ Date._parse('01/02/03', true).must_equal(:year=>2003, :mon=>1, :mday=>2)
95
223
  end
96
224
 
97
225
  specify "should use american date format for d/m/yy" do
98
- Date._parse('1/2/03', true).should == {:year=>2003, :mon=>1, :mday=>2}
99
- Date._parse('1/2/03', false).should == {:year=>3, :mon=>1, :mday=>2}
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)
100
228
  end
101
229
 
102
230
  specify "should use american date format for dd/mm/yyyy" do
103
- Date._parse('01/02/2003').should == {:year=>2003, :mon=>1, :mday=>2}
231
+ Date._parse('01/02/2003').must_equal(:year=>2003, :mon=>1, :mday=>2)
104
232
  end
105
233
 
106
234
  specify "should use american date format for dd/mm" do
107
- Date._parse('01/02').should == {:mon=>1, :mday=>2}
235
+ Date._parse('01/02').must_equal(:mon=>1, :mday=>2)
108
236
  end
109
237
 
110
238
  specify "should use american date format for d/m" do
111
- Date._parse('1/2').should == {:mon=>1, :mday=>2}
239
+ Date._parse('1/2').must_equal(:mon=>1, :mday=>2)
112
240
  end
113
241
 
114
242
  specify "should ignore preceding whitespace" do
115
- Date._parse(' 01/02/2003').should == {:year=>2003, :mon=>1, :mday=>2}
243
+ Date._parse(' 01/02/2003').must_equal(:year=>2003, :mon=>1, :mday=>2)
116
244
  end
117
245
 
118
246
  specify "should work with times" do
119
- DateTime._parse('01/02/2003 10:20:30').should == {:year=>2003, :mon=>1, :mday=>2, :hour=>10, :min=>20, :sec=>30}
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
120
268
  end
121
269
  end
metadata CHANGED
@@ -1,17 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: american_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jeremy Evans
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-12-12 00:00:00.000000000 Z
13
- dependencies: []
14
- description: American style month/day/year date parsing for ruby 1.9
11
+ date: 2021-11-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-global_expectations
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: American style month/day/year date parsing for ruby 1.9+
15
42
  email: code@jeremyevans.net
16
43
  executables: []
17
44
  extensions: []
@@ -20,41 +47,44 @@ extra_rdoc_files:
20
47
  - CHANGELOG
21
48
  - MIT-LICENSE
22
49
  files:
23
- - MIT-LICENSE
24
50
  - CHANGELOG
51
+ - MIT-LICENSE
25
52
  - README.rdoc
26
53
  - Rakefile
27
- - spec/american_date_spec.rb
28
54
  - lib/american_date.rb
55
+ - spec/american_date_keyword_spec.rb
56
+ - spec/american_date_spec.rb
29
57
  homepage: https://github.com/jeremyevans/ruby-american_date
30
- licenses: []
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ bug_tracker_uri: https://github.com/jeremyevans/ruby-american_date/issues
62
+ changelog_uri: https://github.com/jeremyevans/ruby-american_date/blob/master/CHANGELOG
63
+ source_code_uri: https://github.com/jeremyevans/ruby-american_date
31
64
  post_install_message:
32
65
  rdoc_options:
33
- - --quiet
34
- - --inline-source
35
- - --line-numbers
36
- - --title
37
- - ! 'american_date: American style month/day/year date parsing for ruby 1.9'
38
- - --main
66
+ - "--quiet"
67
+ - "--inline-source"
68
+ - "--line-numbers"
69
+ - "--title"
70
+ - 'american_date: American style month/day/year date parsing for ruby 1.9+'
71
+ - "--main"
39
72
  - README.rdoc
40
73
  require_paths:
41
74
  - lib
42
75
  required_ruby_version: !ruby/object:Gem::Requirement
43
- none: false
44
76
  requirements:
45
- - - ! '>='
77
+ - - ">="
46
78
  - !ruby/object:Gem::Version
47
79
  version: '0'
48
80
  required_rubygems_version: !ruby/object:Gem::Requirement
49
- none: false
50
81
  requirements:
51
- - - ! '>='
82
+ - - ">="
52
83
  - !ruby/object:Gem::Version
53
84
  version: '0'
54
85
  requirements: []
55
- rubyforge_project:
56
- rubygems_version: 1.8.11
86
+ rubygems_version: 3.2.22
57
87
  signing_key:
58
- specification_version: 3
59
- summary: American style month/day/year date parsing for ruby 1.9
88
+ specification_version: 4
89
+ summary: American style month/day/year date parsing for ruby 1.9+
60
90
  test_files: []