normalizy 1.3.0 → 1.4.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
2
  SHA256:
3
- metadata.gz: 8300817453468b0e7ff154ffeb0e0f9baf0684564fa7f49f844d83737276a994
4
- data.tar.gz: 00d889cf50054c3706c1a3b4d12e986fad0329778343030376952b0c6d415180
3
+ metadata.gz: 5f14ab0cae60c11869af9ac8bf6fbb51f95d94200f32f72d024dc7374f82e4ed
4
+ data.tar.gz: bb91ac9f34acdeeb0e98d8891bd0dc1d8ddade115af057ad5292ee5925455f46
5
5
  SHA512:
6
- metadata.gz: 96273b202baef19288ebb5f247260dcaea1f0c14a379bf70cb730ece0135398c988cd608e77a4ebb186f07f4597ee6cf8bd4157fe75e1a0144b6a0cad4f7544e
7
- data.tar.gz: d88f9a79b46f80faa874bb391d98eece3f98fbb28fc7396730360cc049fe4e6124d38b04a366745ed45404b14495a1d78a6b2e29350f26de869c875614a511cc
6
+ metadata.gz: dc45e12d2315ef96780d736fcc8554bd78c74f25db2addd6868658c4268196ba64de7c65925798dd8eedc0d31b012a69d542c7725032cb657d4f024900d6adf9
7
+ data.tar.gz: e1f89c0c87861c86291d38ef4be32cff60a110ebed57e2b893fbb3a0c29b66e4ba256d5b486d2194b9af26de7442859720d59d690b5930c46aec058206d6437a
@@ -1,3 +1,7 @@
1
+ ## v1.4.0
2
+
3
+ - Adds `date` support for `Date` class.
4
+
1
5
  ## v1.3.0
2
6
 
3
7
  - Changes:
@@ -13,7 +13,7 @@ module Normalizy
13
13
  end
14
14
  end
15
15
 
16
- if input.is_a?(Time) || input.is_a?(DateTime)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Normalizy
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.0'
5
5
  end
@@ -3,17 +3,8 @@
3
3
  require 'rails_helper'
4
4
 
5
5
  RSpec.describe ModelDate, 'filters:date' do
6
- it do
7
- expected = Time.new(1984, 10, 23, 0, 0, 0, 0)
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, 10, 23), adjust: :end)).to eq Time.new(1984, 10, 23).end_of_day }
13
- it { expect(subject.call(Time.new(1984, 10, 23, 1), adjust: :begin)).to eq Time.new(1984, 10, 23).beginning_of_day }
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
@@ -37,6 +37,8 @@ ActiveRecord::Schema.define(version: 0) do
37
37
  create_table :model_dates do |t|
38
38
  t.datetime :date
39
39
  t.datetime :date_format
40
+ t.datetime :date_time_begin
41
+ t.datetime :date_time_end
40
42
  t.datetime :date_time_zone
41
43
  end
42
44
 
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ModelDate < ActiveRecord::Base
4
- normalizy :date , with: :date
5
- normalizy :date_format , with: { date: { format: '%y/%m/%d' } }
6
- normalizy :date_time_zone, with: { date: { time_zone: 'Brasilia' } }
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.3.0
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: 2019-08-20 00:00:00.000000000 Z
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.0.3
195
+ rubygems_version: 3.1.2
196
196
  signing_key:
197
197
  specification_version: 4
198
198
  summary: Attribute normalizer for ActiveRecord.