infer_model 0.1.4 → 0.1.5

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: 04ed2000c2f891a8afbecbeb147ea60b99f2d75c3e98894037c9858311d38f2c
4
- data.tar.gz: fe283d10e13d59f2579b87639c7707a5e45470bf825b2b71410ff55e1e78bfd4
3
+ metadata.gz: 0db6650dbf15131ccd40e479b1980e85754cd1055e862eede221cca10f3553e9
4
+ data.tar.gz: f6ec28401dda3153ea50a1eb1998d821958dfcf3d98c3f5f8f2160ef2322377b
5
5
  SHA512:
6
- metadata.gz: b88b7f67b42df71dafa09e5b3748a4dca6d3ea7be1c1d36c7a3b9eb834ac906648df33969bbfd8ac426f2ce830206684dd918e72114337f29ef9c1a2f6367b1d
7
- data.tar.gz: c75104eecb2ff301cc46c760dad9c2d4985e93e11546ad0caad799f999bd67788507febadaa72367ee44fd25d4f9eab2b1e07ec8c89418f104cc8885a21f0eaa
6
+ metadata.gz: ea99ee69a52875475ba42929916904c9673ebd605332b0fec90cd8f00132c65956003e9a942babe677320535acb7aaa52c4a8bc42b1415e3060feb248ffda89e
7
+ data.tar.gz: 6cd11aefd834f5549281f58a705d23a9d14f61ce0907e6ed79a5633c35ffb34d5de2f4f593ab9b261d2a38815fc57d7e99c8a730656aa42c01a14e72774a9208
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- infer_model (0.1.4)
4
+ infer_model (0.1.5)
5
5
  activesupport (~> 7.0)
6
6
  dry-initializer (~> 3.0)
7
7
  zeitwerk (~> 2.6)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support"
3
4
  require "date"
4
5
 
5
6
  module InferModel
@@ -22,19 +23,30 @@ module InferModel
22
23
 
23
24
  param :value
24
25
  option :allow_blank, default: -> { true }
25
- option :time_zone_offset, default: -> { "+00:00" }
26
+ option :time_zone_offset, optional: true
27
+ option :time_zone, optional: true
26
28
 
27
29
  def call
28
30
  raise Parsers::Error, "value was blank which is not allowed" if value.nil? && !allow_blank
29
31
  return if value.nil? || value.empty?
30
32
 
31
- datetime_without_zone = parsed_datetime.iso8601[..-7]
32
- datetime_with_custom_zone = datetime_without_zone + time_zone_offset
33
- DateTime.parse(datetime_with_custom_zone)
33
+ # make sure value parsed once before applying time zone
34
+ # so formats are validated
35
+ apply_time_zone(parsed_datetime)
34
36
  end
35
37
 
36
38
  private
37
39
 
40
+ def apply_time_zone(datetime)
41
+ if time_zone_offset
42
+ datetime.change(offset: time_zone_offset)
43
+ elsif time_zone
44
+ Time.use_zone(time_zone) { Time.zone.parse(value) } # discard parsed result and parse again in assumed zone
45
+ else
46
+ datetime
47
+ end
48
+ end
49
+
38
50
  def parsed_datetime
39
51
  ACCEPTABLE_DATETIME_FORMATS.each do |format|
40
52
  return DateTime.strptime(value, format)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InferModel
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infer_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Schneider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-15 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport