interpret_date 1.1.0 → 1.3.4

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
- SHA1:
3
- metadata.gz: 761b3663c400c791352e4930bb3d4cce8cbdc4b4
4
- data.tar.gz: 8d78cc3192b7b4dcd601e1a857affbd04f501c76
2
+ SHA256:
3
+ metadata.gz: b3b8bebb2dfb1221ccbc55fb41f135e517ea5993171ff44868a5dda12dae0d89
4
+ data.tar.gz: 8d9dd65e13bf621c6cdc252a175b0da49f8b1fc5e935325277fd5297d6c2c9b0
5
5
  SHA512:
6
- metadata.gz: 00ac81258a7c023b1ed9fd9de0f0ff9f96ccfd0f2a66d6f4eca0755b2187f35f5d11d8b543f7004194219a5f4930736021fae7c726b6194283e4455b0b42c28a
7
- data.tar.gz: 793feddbc43b71c1c68510eea79d277b94662740a65261563cc4b829c5e4666ceee48b1a0cdbeec1354dfb9643c1a275fbb075cdeacfb5245cc726c12ca71d41
6
+ metadata.gz: ca526eec8ea1b5d198c8d1711c436260bbf37fe41d724089610242b0d4881cfa8516f2c2ec963a61edd1984d02f3abf341b59cfed6288f814f485e2d23a20a35
7
+ data.tar.gz: 0c70c1fa501a24c78b7c8b17228c3f22131c6bee734428fefd6d80234c02012e11883dbf36401bf07dfdbb18c9c083821de217440367f38a02d57b2bee2d79ce
@@ -0,0 +1,25 @@
1
+ name: Build and Publish to RubyGems
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: '2.7'
16
+
17
+ - run: |
18
+ mkdir -p $HOME/.gem
19
+ touch $HOME/.gem/credentials
20
+ chmod 0600 $HOME/.gem/credentials
21
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
22
+ gem build *.gemspec
23
+ gem push *.gem
24
+ env:
25
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
@@ -0,0 +1,17 @@
1
+ name: Verify Gem Version Change
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [ master ]
6
+
7
+ jobs:
8
+ build:
9
+ name: Version Check
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Version Forget Me Not
14
+ uses: simplybusiness/version-forget-me-not@v2
15
+ env:
16
+ ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17
+ VERSION_FILE_PATH: "lib/interpret_date/version.rb"
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0
6
- - 2.1
7
4
  - 2.2
5
+ - ruby-2.3.1
6
+ - ruby-2.4.0
data/README.md CHANGED
@@ -21,6 +21,8 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
+ ### Instance Methods
25
+
24
26
  To utilize `interpret_date`, mix in the `InterpretDate` module into a
25
27
  class that needs to interpret American formatted dates into ruby Date
26
28
  objects and pass the date string into the `interpret_date` or
@@ -42,6 +44,31 @@ class Parcel < ActiveRecord::Base
42
44
  end
43
45
  ```
44
46
 
47
+ ### ActiveRecord Date Type
48
+
49
+ You can also utilize `InterpretDate` with the ActiveRecord Attribute
50
+ API to automatically cast dates with their interpreted values.
51
+
52
+ ```ruby
53
+ class Parcel < ActiveRecord::Base
54
+ attribute :shipping_date, InterpretDate::DateType.new
55
+ end
56
+ ```
57
+
58
+ If you plan on using the Date Type extensively you can register it in
59
+ an initializer.
60
+
61
+ ```ruby
62
+ # config/initializers/types.rb
63
+ ActiveRecord::Type.register(:interpreted_date, InterpretDate::DateType)
64
+ ```
65
+
66
+ ```ruby
67
+ class Parcel < ActiveRecord::Base
68
+ attribute :shipping_date, :interpreted_date
69
+ end
70
+ ```
71
+
45
72
  ## Contributing
46
73
 
47
74
  1. Fork it ( https://github.com/sqm/interpret_date/fork )
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency 'activerecord', ['>= 5.1', '< 7']
21
22
  spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rake", "~> 12"
23
24
  spec.add_development_dependency "rspec", "~> 3.2"
24
25
  end
@@ -0,0 +1,11 @@
1
+ require "active_record"
2
+
3
+ module InterpretDate
4
+ class DateType < ActiveRecord::Type::Date
5
+ include InterpretDate
6
+
7
+ def cast(value)
8
+ super(interpret_date(value) || value)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module InterpretDate
2
- VERSION = "1.1.0"
2
+ VERSION = "1.3.4"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require "date"
2
+ require "interpret_date/date_type"
1
3
  require "interpret_date/version"
2
4
 
3
5
  module InterpretDate
@@ -24,6 +26,10 @@ module InterpretDate
24
26
  /^\d{6}$/ =~ value
25
27
  end
26
28
 
29
+ def contains_only_eight_digits(value)
30
+ /^\d{8}$/ =~ value
31
+ end
32
+
27
33
  def convert_date(date_input)
28
34
  # Only run the interpret_date code if we have a non-nil string,
29
35
  # otherwise, use #to_date to strip any time or timezone info
@@ -35,6 +41,12 @@ module InterpretDate
35
41
  month = date_input[0,2].to_i
36
42
  day = date_input[2,2].to_i
37
43
  year = date_input[4,2].to_i
44
+ elsif contains_only_eight_digits(date_input)
45
+ # The date_input only contains digits, and must
46
+ # be in the form MMDDYYYY
47
+ month = date_input[0,2].to_i
48
+ day = date_input[2,2].to_i
49
+ year = date_input[4,4].to_i
38
50
  elsif db_formatted_date(date_input)
39
51
  year, month, day = date_input.split("-").collect { |element| element.to_i }
40
52
  elsif slash_based_date(date_input)
@@ -6,6 +6,7 @@ RSpec.describe InterpretDate do
6
6
 
7
7
  {
8
8
  "mmddyy" => "020690",
9
+ "mmddyyyy" => "02061990",
9
10
  "m/d/yy" => "2/6/90",
10
11
  "m/d/yyyy" => "2/6/1990",
11
12
  "mm/dd/yy" => "02/06/90",
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interpret_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Squaremouth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-03 00:00:00.000000000 Z
11
+ date: 2022-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '5.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: bundler
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -28,16 +48,16 @@ dependencies:
28
48
  name: rake
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
- - - ">="
51
+ - - "~>"
32
52
  - !ruby/object:Gem::Version
33
- version: '0'
53
+ version: '12'
34
54
  type: :development
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
37
57
  requirements:
38
- - - ">="
58
+ - - "~>"
39
59
  - !ruby/object:Gem::Version
40
- version: '0'
60
+ version: '12'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: rspec
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -60,6 +80,8 @@ executables: []
60
80
  extensions: []
61
81
  extra_rdoc_files: []
62
82
  files:
83
+ - ".github/workflows/gem-push.yml"
84
+ - ".github/workflows/gem-version-check.yml"
63
85
  - ".gitignore"
64
86
  - ".rspec"
65
87
  - ".travis.yml"
@@ -69,6 +91,7 @@ files:
69
91
  - Rakefile
70
92
  - interpret_date.gemspec
71
93
  - lib/interpret_date.rb
94
+ - lib/interpret_date/date_type.rb
72
95
  - lib/interpret_date/version.rb
73
96
  - spec/interpret_date_spec.rb
74
97
  - spec/spec_helper.rb
@@ -91,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
114
  - !ruby/object:Gem::Version
92
115
  version: '0'
93
116
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.5.1
117
+ rubygems_version: 3.1.6
96
118
  signing_key:
97
119
  specification_version: 4
98
120
  summary: Mixin for easily parsing American formatted date strings into Date objects.