american_date 1.1.1 → 1.2.0

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
- SHA1:
3
- metadata.gz: 639c1dccbfe0dbf670569aaffb560c53ad3dac27
4
- data.tar.gz: 0e6ab6b8a1847e58c5ef5cf4d93228b0f26f61f2
2
+ SHA256:
3
+ metadata.gz: 2fd9a4c53baa027ff94f1802a0f51e78bdc68fc9892d49152072b8eb2205f671
4
+ data.tar.gz: d56ba6c7c8a88eeb79a2993fac0c3eb69c2318437a3299eaf087e94213720ce1
5
5
  SHA512:
6
- metadata.gz: e730ca1a4deae09680360f844048476abb5ea396c94222933fdf7687f20c1f6469925fd80c4599825c7cc5ea27cf0f11d7fe77b503f8dec59eb02790e82f8100
7
- data.tar.gz: 2c69087b54b406a9b332ad65ae9b1cb0bbef7bf2c787b49ea5b7e864158e4f0b7f1541e6f40741796171e31d881aba094afa0758e6e836766e728baf84893ba8
6
+ metadata.gz: dfd6235350c26f3ed600bdcc5a6497cb9633666bda0df00c7129d142f145edd8fe6e14a8e9aa8b82398abf3210141e50d09a4c2c12021da69183cd3a691282cf
7
+ data.tar.gz: dc035e0b03255603061bd2a419250ab05c57187c60b441b64afe0de3a2730f620e594c46f7a7c7a2b67dfdbc3025c2c9583a2c840306a8db95e98793454461a5
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.2.0 (2021-11-17)
2
+
3
+ * Support the limit keyword argument supported by date 3.2.1+ (jeremyevans)
4
+
1
5
  === 1.1.1 (2015-10-27)
2
6
 
3
7
  * Support the third argument to Date/DateTime.parse (costi) (#13)
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011,2013 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
@@ -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 version, but it is basically
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/Rakefile CHANGED
@@ -26,7 +26,7 @@ end
26
26
 
27
27
  desc "Run specs"
28
28
  task :spec do
29
- sh "#{FileUtils::RUBY} -rubygems -I lib spec/american_date_spec.rb"
29
+ sh "#{FileUtils::RUBY} -I lib spec/american_date_spec.rb"
30
30
  end
31
31
  task :default=>[:spec]
32
32
 
data/lib/american_date.rb CHANGED
@@ -1,8 +1,17 @@
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
16
  AMERICAN_DATE_RE = eval('%r_(?<!\d)(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})(?!\d)_').freeze
8
17
  # Negative lookbehinds, which are not supported in Ruby 1.8
@@ -12,18 +21,34 @@ if RUBY_VERSION >= '1.9'
12
21
  # Alias for stdlib Date._parse
13
22
  alias _parse_without_american_date _parse
14
23
 
15
- # Transform american dates into ISO dates before parsing.
16
- def _parse(string, comp=true)
17
- _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
18
35
  end
19
36
 
20
37
  if RUBY_VERSION >= '1.9.3'
21
38
  # Alias for stdlib Date.parse
22
39
  alias parse_without_american_date parse
23
40
 
24
- # Transform american dates into ISO dates before parsing.
25
- def parse(string, comp=true, start=Date::ITALY)
26
- parse_without_american_date(convert_american_to_iso(string), comp, start)
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
27
52
  end
28
53
  end
29
54
 
@@ -48,13 +73,21 @@ if RUBY_VERSION >= '1.9'
48
73
 
49
74
  if RUBY_VERSION >= '1.9.3'
50
75
  # Modify parsing methods to handle american date format correctly.
51
- class << DateTime
76
+ DateTime.instance_eval do
52
77
  # Alias for stdlib Date.parse
53
78
  alias parse_without_american_date parse
54
79
 
55
- # Transform american dates into ISO dates before parsing.
56
- def parse(string, comp=true, start=DateTime::ITALY)
57
- parse_without_american_date(convert_american_to_iso(string), comp, start)
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
58
91
  end
59
92
  end
60
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,6 +1,13 @@
1
1
  require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib', 'american_date')
2
2
  require 'time'
3
- require 'minitest/autorun'
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
4
11
 
5
12
  describe "Date.parse" do
6
13
  specify "should use american date format for dd/mm/yy" do
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.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-28 00:00:00.000000000 Z
12
- dependencies: []
13
- 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+
14
42
  email: code@jeremyevans.net
15
43
  executables: []
16
44
  extensions: []
@@ -24,17 +52,22 @@ files:
24
52
  - README.rdoc
25
53
  - Rakefile
26
54
  - lib/american_date.rb
55
+ - spec/american_date_keyword_spec.rb
27
56
  - spec/american_date_spec.rb
28
57
  homepage: https://github.com/jeremyevans/ruby-american_date
29
- licenses: []
30
- metadata: {}
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
66
  - "--quiet"
34
67
  - "--inline-source"
35
68
  - "--line-numbers"
36
69
  - "--title"
37
- - 'american_date: American style month/day/year date parsing for ruby 1.9'
70
+ - 'american_date: American style month/day/year date parsing for ruby 1.9+'
38
71
  - "--main"
39
72
  - README.rdoc
40
73
  require_paths:
@@ -50,9 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
83
  - !ruby/object:Gem::Version
51
84
  version: '0'
52
85
  requirements: []
53
- rubyforge_project:
54
- rubygems_version: 2.4.5.1
86
+ rubygems_version: 3.2.22
55
87
  signing_key:
56
88
  specification_version: 4
57
- summary: American style month/day/year date parsing for ruby 1.9
89
+ summary: American style month/day/year date parsing for ruby 1.9+
58
90
  test_files: []