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 +5 -5
- data/.github/workflows/gem-push.yml +25 -0
- data/.github/workflows/gem-version-check.yml +17 -0
- data/.travis.yml +2 -3
- data/README.md +27 -0
- data/interpret_date.gemspec +2 -1
- data/lib/interpret_date/date_type.rb +11 -0
- data/lib/interpret_date/version.rb +1 -1
- data/lib/interpret_date.rb +12 -0
- data/spec/interpret_date_spec.rb +1 -0
- metadata +30 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b3b8bebb2dfb1221ccbc55fb41f135e517ea5993171ff44868a5dda12dae0d89
|
4
|
+
data.tar.gz: 8d9dd65e13bf621c6cdc252a175b0da49f8b1fc5e935325277fd5297d6c2c9b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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 )
|
data/interpret_date.gemspec
CHANGED
@@ -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
|
data/lib/interpret_date.rb
CHANGED
@@ -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)
|
data/spec/interpret_date_spec.rb
CHANGED
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.
|
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:
|
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: '
|
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: '
|
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
|
-
|
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.
|