normalizy 1.3.0 → 1.4.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/normalizy/filters/date.rb +1 -1
- data/lib/normalizy/version.rb +1 -1
- data/spec/normalizy/extensions/filters/date_spec.rb +10 -11
- data/spec/normalizy/filters/date_spec.rb +21 -2
- data/spec/support/db/schema.rb +2 -0
- data/spec/support/models/model_date.rb +5 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f14ab0cae60c11869af9ac8bf6fbb51f95d94200f32f72d024dc7374f82e4ed
|
4
|
+
data.tar.gz: bb91ac9f34acdeeb0e98d8891bd0dc1d8ddade115af057ad5292ee5925455f46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc45e12d2315ef96780d736fcc8554bd78c74f25db2addd6868658c4268196ba64de7c65925798dd8eedc0d31b012a69d542c7725032cb657d4f024900d6adf9
|
7
|
+
data.tar.gz: e1f89c0c87861c86291d38ef4be32cff60a110ebed57e2b893fbb3a0c29b66e4ba256d5b486d2194b9af26de7442859720d59d690b5930c46aec058206d6437a
|
data/CHANGELOG.md
CHANGED
@@ -13,7 +13,7 @@ module Normalizy
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
if
|
16
|
+
if [::Date, DateTime, Time].include?(input.class)
|
17
17
|
input = input.beginning_of_day if options[:adjust] == :begin
|
18
18
|
input = input.end_of_day if options[:adjust] == :end
|
19
19
|
end
|
data/lib/normalizy/version.rb
CHANGED
@@ -3,17 +3,8 @@
|
|
3
3
|
require 'rails_helper'
|
4
4
|
|
5
5
|
RSpec.describe ModelDate, 'filters:date' do
|
6
|
-
it
|
7
|
-
|
8
|
-
|
9
|
-
expect(described_class.create(date: '1984-10-23').date).to eq expected
|
10
|
-
end
|
11
|
-
|
12
|
-
it do
|
13
|
-
expected = Time.new(1984, 10, 23, 0, 0, 0, 0)
|
14
|
-
|
15
|
-
expect(described_class.create(date_format: '84/10/23').date_format).to eq expected
|
16
|
-
end
|
6
|
+
it { expect(described_class.create(date: '1984-10-23').date).to eq(Time.new(1984, 10, 23, 0, 0, 0, 0)) }
|
7
|
+
it { expect(described_class.create(date_format: '84/10/23').date_format).to eq(Time.new(1984, 10, 23, 0, 0, 0, 0)) }
|
17
8
|
|
18
9
|
it do
|
19
10
|
hours = ActiveSupport::TimeZone['Brasilia'].utc_offset / 3600.0
|
@@ -21,4 +12,12 @@ RSpec.describe ModelDate, 'filters:date' do
|
|
21
12
|
|
22
13
|
expect(described_class.create(date_time_zone: '1984-10-23').date_time_zone).to eq expected
|
23
14
|
end
|
15
|
+
|
16
|
+
it 'normalizys end date' do
|
17
|
+
expect(described_class.new(date_time_end: Date.new(1984)).date_time_end).to eq(Time.new(1984).end_of_day)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'normalizys begin date' do
|
21
|
+
expect(described_class.new(date_time_begin: Date.new(1984, 10, 23)).date_time_begin).to eq(Time.new(1984, 10, 23))
|
22
|
+
end
|
24
23
|
end
|
@@ -9,8 +9,27 @@ RSpec.describe Normalizy::Filters::Date do
|
|
9
9
|
|
10
10
|
it { expect(subject.call('84/10/23', format: '%y/%m/%d')).to eq Time.new(1984, 10, 23, 0, 0, 0, 0) }
|
11
11
|
|
12
|
-
it { expect(subject.call(Time.new(1984,
|
13
|
-
it { expect(subject.call(Time.new(1984
|
12
|
+
it { expect(subject.call(Time.new(1984, 1, 1, 1), adjust: :begin)).to eq Time.new(1984) }
|
13
|
+
it { expect(subject.call(Time.new(1984), adjust: :end)).to eq Time.new(1984).end_of_day }
|
14
|
+
|
15
|
+
it { expect(subject.call(DateTime.new(1984, 1, 1, 1), adjust: :begin)).to eq DateTime.new(1984) }
|
16
|
+
it { expect(subject.call(DateTime.new(1984), adjust: :end)).to eq DateTime.new(1984).end_of_day }
|
17
|
+
|
18
|
+
it do
|
19
|
+
result = subject.call(Date.new(1984, 10, 23), adjust: :end)
|
20
|
+
|
21
|
+
expect(result.year).to eq 1984
|
22
|
+
expect(result.month).to eq 10
|
23
|
+
expect(result.day).to eq 23
|
24
|
+
end
|
25
|
+
|
26
|
+
it do
|
27
|
+
result = subject.call(Date.new(1984), adjust: :end)
|
28
|
+
|
29
|
+
expect(result.year).to eq 1984
|
30
|
+
expect(result.month).to eq 1
|
31
|
+
expect(result.day).to eq 1
|
32
|
+
end
|
14
33
|
|
15
34
|
it 'accepts time zone' do
|
16
35
|
time = subject.call('1984-10-23', time_zone: 'Tokelau Is.').utc
|
data/spec/support/db/schema.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class ModelDate < ActiveRecord::Base
|
4
|
-
normalizy :date
|
5
|
-
normalizy :date_format
|
6
|
-
normalizy :
|
4
|
+
normalizy :date , with: :date
|
5
|
+
normalizy :date_format, with: { date: { format: '%y/%m/%d' } }
|
6
|
+
normalizy :date_time_begin, with: { date: { adjust: :begin } }
|
7
|
+
normalizy :date_time_end, with: { date: { adjust: :end } }
|
8
|
+
normalizy :date_time_zone, with: { date: { time_zone: 'Brasilia' } }
|
7
9
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: normalizy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Washington Botelho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
192
|
- !ruby/object:Gem::Version
|
193
193
|
version: '0'
|
194
194
|
requirements: []
|
195
|
-
rubygems_version: 3.
|
195
|
+
rubygems_version: 3.1.2
|
196
196
|
signing_key:
|
197
197
|
specification_version: 4
|
198
198
|
summary: Attribute normalizer for ActiveRecord.
|