american_date 1.1.1 → 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 +5 -5
- data/CHANGELOG +8 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -7
- data/lib/american_date.rb +65 -17
- metadata +44 -15
- data/Rakefile +0 -37
- data/spec/american_date_spec.rb +0 -262
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7ad1d14cdbbdd03f5c6eef433b17dbb9e5bd296a1a244ce25cf2dec846ef5f4c
|
|
4
|
+
data.tar.gz: 66ca9d13ae079e149a3b2d7228b62cacde0a9b722f28450caf50bd0910c778e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1bd9aab61e47d7fc2ad2a1ca41181fbda894675d9afcfe718cf9c2de55663b6901b5cb7655392084b6479e9968c3423a0308895d1dfc1e1f7c5cfb392a8ab53e
|
|
7
|
+
data.tar.gz: c8a4d9579fc57d4cac21142d6cd7a5e36f44b05642fa5d5e9ea3b0907523b03199bc66d1193b4f10187848ab5dbbb02e24869d357a539e976acd71fe7057b45c
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
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
|
+
|
|
5
|
+
=== 1.2.0 (2021-11-17)
|
|
6
|
+
|
|
7
|
+
* Support the limit keyword argument supported by date 3.2.1+ (jeremyevans)
|
|
8
|
+
|
|
1
9
|
=== 1.1.1 (2015-10-27)
|
|
2
10
|
|
|
3
11
|
* Support the third argument to Date/DateTime.parse (costi) (#13)
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
ruby-american_date exists to make ruby 1.9+ parse american-style
|
|
4
4
|
month/day/year dates correctly, with behavior matching ruby 1.8.7.
|
|
5
|
-
It can also be used on earlier ruby
|
|
5
|
+
It can also be used on earlier ruby versions, but it is basically
|
|
6
6
|
a noop there.
|
|
7
7
|
|
|
8
8
|
As far as I know, there isn't a gem that already handles this. You
|
|
@@ -25,12 +25,6 @@ standard date parsing methods. This is probably the least invasive
|
|
|
25
25
|
way that works correctly on both the pure-ruby date parser (<1.9.3)
|
|
26
26
|
and the C extension date parser (>=1.9.3).
|
|
27
27
|
|
|
28
|
-
== Tested ruby versions
|
|
29
|
-
|
|
30
|
-
* ruby 1.8.6, 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1.0
|
|
31
|
-
* rubinius 1.2.4, 2.2.6
|
|
32
|
-
* jruby 1.6.5, 1.7.9 (both --1.8 and --1.9 modes)
|
|
33
|
-
|
|
34
28
|
== Installation
|
|
35
29
|
|
|
36
30
|
ruby-american_date is distributed as a gem, and can be installed with:
|
data/lib/american_date.rb
CHANGED
|
@@ -1,30 +1,66 @@
|
|
|
1
1
|
require 'date'
|
|
2
2
|
|
|
3
|
+
# :nocov:
|
|
3
4
|
if RUBY_VERSION >= '1.9'
|
|
5
|
+
# :nocov:
|
|
6
|
+
long_date = ' ' * 128 + '2021-10-11'
|
|
7
|
+
limit_supported = begin
|
|
8
|
+
Date.parse(long_date)
|
|
9
|
+
rescue ArgumentError
|
|
10
|
+
(Date.parse(long_date, true, Date::ITALY, :limit=>nil) == Date.new(2021, 10, 11)) rescue false
|
|
11
|
+
# :nocov:
|
|
12
|
+
else
|
|
13
|
+
false
|
|
14
|
+
# :nocov:
|
|
15
|
+
end
|
|
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
|
+
|
|
4
23
|
# Modify parsing methods to handle american date format correctly.
|
|
5
|
-
|
|
6
|
-
# American date format detected by the library.
|
|
7
|
-
AMERICAN_DATE_RE = eval('%r_(?<!\d)(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})(?!\d)_').freeze
|
|
8
|
-
# Negative lookbehinds, which are not supported in Ruby 1.8
|
|
9
|
-
# so by using eval, we prevent an error when this file is first parsed
|
|
10
|
-
# since the regexp itself will only be parsed at runtime if the RUBY_VERSION condition is met.
|
|
24
|
+
Date.instance_eval do
|
|
11
25
|
|
|
12
26
|
# Alias for stdlib Date._parse
|
|
13
27
|
alias _parse_without_american_date _parse
|
|
14
28
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
29
|
+
if limit_supported
|
|
30
|
+
instance_eval(<<-END, __FILE__, __LINE__+1)
|
|
31
|
+
def _parse(string, comp=true, limit: 128)
|
|
32
|
+
_parse_without_american_date(convert_american_to_iso(string), comp, limit: limit)
|
|
33
|
+
end
|
|
34
|
+
END
|
|
35
|
+
# :nocov:
|
|
36
|
+
else
|
|
37
|
+
# Transform american dates into ISO dates before parsing.
|
|
38
|
+
def _parse(string, comp=true)
|
|
39
|
+
_parse_without_american_date(convert_american_to_iso(string), comp)
|
|
40
|
+
end
|
|
41
|
+
# :nocov:
|
|
18
42
|
end
|
|
19
43
|
|
|
44
|
+
# :nocov:
|
|
20
45
|
if RUBY_VERSION >= '1.9.3'
|
|
46
|
+
# :nocov:
|
|
21
47
|
# Alias for stdlib Date.parse
|
|
22
48
|
alias parse_without_american_date parse
|
|
23
49
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
50
|
+
if limit_supported
|
|
51
|
+
instance_eval(<<-END, __FILE__, __LINE__+1)
|
|
52
|
+
def parse(string, comp=true, start=Date::ITALY, limit: 128)
|
|
53
|
+
parse_without_american_date(convert_american_to_iso(string), comp, start, limit: limit)
|
|
54
|
+
end
|
|
55
|
+
END
|
|
56
|
+
# :nocov:
|
|
57
|
+
else
|
|
58
|
+
# Transform american dates into ISO dates before parsing.
|
|
59
|
+
def parse(string, comp=true, start=Date::ITALY)
|
|
60
|
+
parse_without_american_date(convert_american_to_iso(string), comp, start)
|
|
61
|
+
end
|
|
27
62
|
end
|
|
63
|
+
# :nocov:
|
|
28
64
|
end
|
|
29
65
|
|
|
30
66
|
private
|
|
@@ -42,20 +78,32 @@ if RUBY_VERSION >= '1.9'
|
|
|
42
78
|
raise TypeError, "no implicit conversion of #{string.inspect} into String"
|
|
43
79
|
end
|
|
44
80
|
end
|
|
45
|
-
string.sub(AMERICAN_DATE_RE){|m| "#$3-#$1-#$2"}
|
|
81
|
+
string.sub(Date::AMERICAN_DATE_RE){|m| "#$3-#$1-#$2"}
|
|
46
82
|
end
|
|
47
83
|
end
|
|
48
84
|
|
|
85
|
+
# :nocov:
|
|
49
86
|
if RUBY_VERSION >= '1.9.3'
|
|
87
|
+
# :nocov:
|
|
50
88
|
# Modify parsing methods to handle american date format correctly.
|
|
51
|
-
|
|
89
|
+
DateTime.instance_eval do
|
|
52
90
|
# Alias for stdlib Date.parse
|
|
53
91
|
alias parse_without_american_date parse
|
|
54
92
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
93
|
+
if limit_supported
|
|
94
|
+
instance_eval(<<-END, __FILE__, __LINE__+1)
|
|
95
|
+
def parse(string, comp=true, start=Date::ITALY, limit: 128)
|
|
96
|
+
parse_without_american_date(convert_american_to_iso(string), comp, start, limit: limit)
|
|
97
|
+
end
|
|
98
|
+
END
|
|
99
|
+
# :nocov:
|
|
100
|
+
else
|
|
101
|
+
# Transform american dates into ISO dates before parsing.
|
|
102
|
+
def parse(string, comp=true, start=Date::ITALY)
|
|
103
|
+
parse_without_american_date(convert_american_to_iso(string), comp, start)
|
|
104
|
+
end
|
|
58
105
|
end
|
|
106
|
+
# :nocov:
|
|
59
107
|
end
|
|
60
108
|
end
|
|
61
109
|
end
|
metadata
CHANGED
|
@@ -1,16 +1,44 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: american_date
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
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:
|
|
12
|
-
dependencies:
|
|
13
|
-
|
|
11
|
+
date: 2023-07-13 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+
|
|
14
42
|
email: code@jeremyevans.net
|
|
15
43
|
executables: []
|
|
16
44
|
extensions: []
|
|
@@ -22,19 +50,21 @@ files:
|
|
|
22
50
|
- CHANGELOG
|
|
23
51
|
- MIT-LICENSE
|
|
24
52
|
- README.rdoc
|
|
25
|
-
- Rakefile
|
|
26
53
|
- lib/american_date.rb
|
|
27
|
-
- spec/american_date_spec.rb
|
|
28
54
|
homepage: https://github.com/jeremyevans/ruby-american_date
|
|
29
|
-
licenses:
|
|
30
|
-
|
|
31
|
-
|
|
55
|
+
licenses:
|
|
56
|
+
- MIT
|
|
57
|
+
metadata:
|
|
58
|
+
bug_tracker_uri: https://github.com/jeremyevans/ruby-american_date/issues
|
|
59
|
+
changelog_uri: https://github.com/jeremyevans/ruby-american_date/blob/master/CHANGELOG
|
|
60
|
+
source_code_uri: https://github.com/jeremyevans/ruby-american_date
|
|
61
|
+
post_install_message:
|
|
32
62
|
rdoc_options:
|
|
33
63
|
- "--quiet"
|
|
34
64
|
- "--inline-source"
|
|
35
65
|
- "--line-numbers"
|
|
36
66
|
- "--title"
|
|
37
|
-
- 'american_date: American style month/day/year date parsing for ruby 1.9'
|
|
67
|
+
- 'american_date: American style month/day/year date parsing for ruby 1.9+'
|
|
38
68
|
- "--main"
|
|
39
69
|
- README.rdoc
|
|
40
70
|
require_paths:
|
|
@@ -50,9 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
50
80
|
- !ruby/object:Gem::Version
|
|
51
81
|
version: '0'
|
|
52
82
|
requirements: []
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
signing_key:
|
|
83
|
+
rubygems_version: 3.4.10
|
|
84
|
+
signing_key:
|
|
56
85
|
specification_version: 4
|
|
57
|
-
summary: American style month/day/year date parsing for ruby 1.9
|
|
86
|
+
summary: American style month/day/year date parsing for ruby 1.9+
|
|
58
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} -rubygems -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
|
data/spec/american_date_spec.rb
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib', 'american_date')
|
|
2
|
-
require 'time'
|
|
3
|
-
require 'minitest/autorun'
|
|
4
|
-
|
|
5
|
-
describe "Date.parse" do
|
|
6
|
-
specify "should use american date format for dd/mm/yy" do
|
|
7
|
-
Date.parse('01/02/03', true).must_equal Date.new(2003, 1, 2)
|
|
8
|
-
Date.parse('01/02/03', true, Date::ITALY).must_equal Date.new(2003, 1, 2)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
specify "should use american date format for d/m/yy" do
|
|
12
|
-
Date.parse('1/2/03', true).must_equal Date.new(2003, 1, 2)
|
|
13
|
-
Date.parse('1/2/03', false).must_equal Date.new(3, 1, 2)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
specify "should use american date format for dd/mm/yyyy" do
|
|
17
|
-
Date.parse('01/02/2003').must_equal Date.new(2003, 1, 2)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
specify "should use american date format for dd/mm" do
|
|
21
|
-
Date.parse('01/02').must_equal Date.new(Time.now.year, 1, 2)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
specify "should use american date format for d/m" do
|
|
25
|
-
Date.parse('1/2').must_equal Date.new(Time.now.year, 1, 2)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
specify "should ignore preceding whitespace" do
|
|
29
|
-
Date.parse(' 01/02/2003').must_equal Date.new(2003, 1, 2)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
specify "should ignore preceding weekday" do
|
|
33
|
-
Date.parse('Day 01/02/2003').must_equal Date.new(2003, 1, 2)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
specify "should work just like 1.8 does" do
|
|
37
|
-
Date.parse('10:20:30something01/02/2003else').must_equal Date.new(2003, 1, 2)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
specify "should not mismatch years" do
|
|
41
|
-
Date.parse('2003/01/02').must_equal Date.new(2003, 1, 2)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
specify "should behave like 1.8 and only allow / as delimiters in american-style dates" do
|
|
45
|
-
Date.parse("10/11/2012").must_equal Date.new(2012, 10, 11)
|
|
46
|
-
Date.parse("10-11-2012").must_equal Date.new(2012, 11, 10)
|
|
47
|
-
Date.parse("10.11.2012").must_equal Date.new(2012, 11, 10)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
if RUBY_VERSION > '1.9'
|
|
51
|
-
specify "should raise TypeError for invalid values" do
|
|
52
|
-
[nil, 1, 1.0, [], {}].each do |x|
|
|
53
|
-
proc{Date.parse(x)}.must_raise(TypeError)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
specify "should handle values implicitly convertible to String" do
|
|
58
|
-
o = Object.new
|
|
59
|
-
def o.to_str() '01/02/2003' end
|
|
60
|
-
Date.parse(o).must_equal Date.new(2003, 1, 2)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
specify "should handle values implicitly convertible to String" do
|
|
64
|
-
o = Object.new
|
|
65
|
-
def o.to_str() 1 end
|
|
66
|
-
proc{Date.parse(o)}.must_raise(TypeError)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe "DateTime.parse" do
|
|
72
|
-
specify "should use american date format for dd/mm/yy" do
|
|
73
|
-
DateTime.parse('01/02/03', true).must_equal DateTime.new(2003, 1, 2)
|
|
74
|
-
DateTime.parse('01/02/03', true, DateTime::ITALY).must_equal DateTime.new(2003, 1, 2)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
specify "should use american date format for d/m/yy" do
|
|
78
|
-
DateTime.parse('1/2/03', true).must_equal DateTime.new(2003, 1, 2)
|
|
79
|
-
DateTime.parse('1/2/03', false).must_equal DateTime.new(3, 1, 2)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
specify "should use american date format for dd/mm/yyyy" do
|
|
83
|
-
DateTime.parse('01/02/2003').must_equal DateTime.new(2003, 1, 2)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
specify "should use american date format for dd/mm" do
|
|
87
|
-
DateTime.parse('01/02').must_equal DateTime.new(Time.now.year, 1, 2)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
specify "should use american date format for d/m" do
|
|
91
|
-
DateTime.parse('1/2').must_equal DateTime.new(Time.now.year, 1, 2)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
specify "should ignore preceding whitespace" do
|
|
95
|
-
DateTime.parse(' 01/02/2003').must_equal DateTime.new(2003, 1, 2)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
specify "should ignore preceding weekday" do
|
|
99
|
-
DateTime.parse('Day 01/02/2003').must_equal Date.new(2003, 1, 2)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
specify "should work with times" do
|
|
103
|
-
DateTime.parse('01/02/2003 10:20:30').must_equal DateTime.new(2003, 1, 2, 10, 20, 30)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
specify "should work with times and weekdays" do
|
|
107
|
-
DateTime.parse('Day 01/02/2003 10:20:30').must_equal DateTime.new(2003, 1, 2, 10, 20, 30)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
specify "should work just like 1.8 does" do
|
|
111
|
-
DateTime.parse('10:20:30something01/02/2003else').must_equal DateTime.new(2003, 1, 2, 10, 20, 30)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
specify "should not mismatch years" do
|
|
115
|
-
DateTime.parse('2003/01/02').must_equal Date.new(2003, 1, 2)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
if RUBY_VERSION > '1.9'
|
|
119
|
-
specify "should raise TypeError for invalid values" do
|
|
120
|
-
[nil, 1, 1.0, [], {}].each do |x|
|
|
121
|
-
proc{DateTime.parse(x)}.must_raise(TypeError)
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
specify "should handle values implicitly convertible to String" do
|
|
126
|
-
o = Object.new
|
|
127
|
-
def o.to_str() '01/02/2003' end
|
|
128
|
-
DateTime.parse(o).must_equal DateTime.new(2003, 1, 2)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
specify "should handle values implicitly convertible to String" do
|
|
132
|
-
o = Object.new
|
|
133
|
-
def o.to_str() 1 end
|
|
134
|
-
proc{DateTime.parse(o)}.must_raise(TypeError)
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
describe "Time.parse" do
|
|
140
|
-
specify "should use american date format for dd/mm/yy" do
|
|
141
|
-
Time.parse('01/02/03').must_equal Time.local(2003, 1, 2)
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
specify "should use american date format for d/m/yy" do
|
|
145
|
-
Time.parse('1/2/03').must_equal Time.local(2003, 1, 2)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
specify "should use american date format for dd/mm/yyyy" do
|
|
149
|
-
Time.parse('01/02/2003').must_equal Time.local(2003, 1, 2)
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
specify "should use american date format for dd/mm" do
|
|
153
|
-
Time.parse('01/02').must_equal Time.local(Time.now.year, 1, 2)
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
specify "should use american date format for d/m" do
|
|
157
|
-
Time.parse('1/2').must_equal Time.local(Time.now.year, 1, 2)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
specify "should ignore preceding whitespace" do
|
|
161
|
-
Time.parse(' 01/02/2003').must_equal Time.local(2003, 1, 2)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
specify "should ignore preceding weekdays" do
|
|
165
|
-
Time.parse('Day 01/02/2003').must_equal Time.local(2003, 1, 2)
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
specify "should work with times" do
|
|
169
|
-
Time.parse('01/02/2003 10:20:30').must_equal Time.local(2003, 1, 2, 10, 20, 30)
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
specify "should work with times and weekdays" do
|
|
173
|
-
Time.parse('Day 01/02/2003 10:20:30').must_equal Time.local(2003, 1, 2, 10, 20, 30)
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
specify "should work with time first and date second" do
|
|
177
|
-
Time.parse('10:20:30 01/02/2003').must_equal Time.local(2003, 1, 2, 10, 20, 30)
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
specify "should work with time first and date second and weekday in the middle" do
|
|
181
|
-
Time.parse('10:20:30 Thu 01/02/2003').must_equal Time.local(2003, 1, 2, 10, 20, 30)
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
specify "should work just like 1.8 does" do
|
|
185
|
-
Time.parse('10:20:30something01/02/2003else').must_equal Time.local(2003, 1, 2, 10, 20, 30)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
specify "should not mismatch years" do
|
|
189
|
-
Time.parse('2003/01/02').must_equal Time.local(2003, 1, 2, 0, 0, 0)
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
if RUBY_VERSION > '1.9'
|
|
193
|
-
specify "should raise TypeError for invalid values" do
|
|
194
|
-
[nil, 1, 1.0, [], {}].each do |x|
|
|
195
|
-
proc{Time.parse(x)}.must_raise(TypeError)
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
specify "should handle values implicitly convertible to String" do
|
|
200
|
-
o = Object.new
|
|
201
|
-
def o.to_str() '01/02/2003' end
|
|
202
|
-
Time.parse(o).must_equal Time.local(2003, 1, 2)
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
specify "should handle values implicitly convertible to String" do
|
|
206
|
-
o = Object.new
|
|
207
|
-
def o.to_str() 1 end
|
|
208
|
-
proc{Time.parse(o)}.must_raise(TypeError)
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
describe "Date._parse" do
|
|
214
|
-
specify "should use american date format for dd/mm/yy" do
|
|
215
|
-
Date._parse('01/02/03', true).must_equal(:year=>2003, :mon=>1, :mday=>2)
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
specify "should use american date format for d/m/yy" do
|
|
219
|
-
Date._parse('1/2/03', true).must_equal(:year=>2003, :mon=>1, :mday=>2)
|
|
220
|
-
Date._parse('1/2/03', false).must_equal(:year=>3, :mon=>1, :mday=>2)
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
specify "should use american date format for dd/mm/yyyy" do
|
|
224
|
-
Date._parse('01/02/2003').must_equal(:year=>2003, :mon=>1, :mday=>2)
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
specify "should use american date format for dd/mm" do
|
|
228
|
-
Date._parse('01/02').must_equal(:mon=>1, :mday=>2)
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
specify "should use american date format for d/m" do
|
|
232
|
-
Date._parse('1/2').must_equal(:mon=>1, :mday=>2)
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
specify "should ignore preceding whitespace" do
|
|
236
|
-
Date._parse(' 01/02/2003').must_equal(:year=>2003, :mon=>1, :mday=>2)
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
specify "should work with times" do
|
|
240
|
-
DateTime._parse('01/02/2003 10:20:30').must_equal(:year=>2003, :mon=>1, :mday=>2, :hour=>10, :min=>20, :sec=>30)
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
if RUBY_VERSION > '1.9'
|
|
244
|
-
specify "should raise TypeError for invalid values" do
|
|
245
|
-
[nil, 1, 1.0, [], {}].each do |x|
|
|
246
|
-
proc{DateTime._parse(x)}.must_raise(TypeError)
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
specify "should handle values implicitly convertible to String" do
|
|
251
|
-
o = Object.new
|
|
252
|
-
def o.to_str() '01/02/2003' end
|
|
253
|
-
DateTime._parse(o).must_equal(:year=>2003, :mon=>1, :mday=>2)
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
specify "should handle values implicitly convertible to String" do
|
|
257
|
-
o = Object.new
|
|
258
|
-
def o.to_str() 1 end
|
|
259
|
-
proc{DateTime._parse(o)}.must_raise(TypeError)
|
|
260
|
-
end
|
|
261
|
-
end
|
|
262
|
-
end
|