active_type 0.7.1 → 0.7.2

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
  SHA1:
3
- metadata.gz: cc819ae9aa3ea32e2f3b9941e64ed7a6e7e74024
4
- data.tar.gz: 7220d7bd91fdaa551cccb124daabe3ac623b5e93
3
+ metadata.gz: 5b5a76b77fa9b0ebd6d4848a56f7029f164aa482
4
+ data.tar.gz: a9dc6dcfba3488aa7a93a0b4d31f7d94e5d62938
5
5
  SHA512:
6
- metadata.gz: f17d366fc2aeffa030b6950920bce04ee91229ba7531b48555a5d96a29fc4882fe3f696b99906cc1fc08f08d42a18de0e2860bc9268c6513c08414fd95b7698e
7
- data.tar.gz: b0aa279cbff3af11b254a39006767f8b16a0c295b3f1bdf635e2df6c84697289bc2154869f308fba5e59c8d23a68917f7e4e37ed47746bbe0adfbc9f0839dde4
6
+ metadata.gz: c3009761aea806e2c41e231bf01e3fdf875398e7defaa267d90294c2cf9c05ebc71690cc0500437ec889192fc644e720d234c349835e327c0e1417c4d2320ca1
7
+ data.tar.gz: 9cb6903641b55d50b83d80d6ca1b2335347cebf8956a00bb1e775eaf6cd445228321ca6f504de94c8e67210bfc93943e05715d3575e2814e523dca8e390f14f8
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ActiveType is in a pre-1.0 state. This means that its APIs and behavior are subject to breaking changes without deprecation notices. Until 1.0, version numbers will follow a [Semver][]-ish `0.y.z` format, where `y` is incremented when new features or breaking changes are introduced, and `z` is incremented for lesser changes or bug fixes.
6
6
 
7
+
8
+ ## [0.7.2][] (2017-07-31)
9
+
10
+ * Fixed a bug when converting datetimes from certain strings. This occured if the string included an explicit time zone (i.e. `record.date_time = '2017-07-31 12:30+03:00'`), which was not the local time.
11
+
7
12
  ## [0.7.1][] (2017-06-19)
8
13
 
9
14
  * ActiveType::Object no longer requires a database connection on Rails 5+ (it never did on Rails 3 or 4).
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.7.1)
4
+ active_type (0.7.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -22,17 +22,9 @@ module ActiveType
22
22
  # outside the classes that have that responsibility.
23
23
  case @type
24
24
  when :integer
25
- if value == ''
26
- nil
27
- else
28
- native_type_cast_from_user(value)
29
- end
25
+ cast_integer(value)
30
26
  when :timestamp, :datetime
31
- time = native_type_cast_from_user(value)
32
- if time && ActiveRecord::Base.time_zone_aware_attributes
33
- time = ActiveSupport::TimeWithZone.new(nil, Time.zone, time)
34
- end
35
- time
27
+ cast_time(value)
36
28
  else
37
29
  native_type_cast_from_user(value)
38
30
  end
@@ -42,6 +34,36 @@ module ActiveType
42
34
  @native_caster.type_cast_from_user(value)
43
35
  end
44
36
 
37
+ private
38
+
39
+ def cast_integer(value)
40
+ if value == ''
41
+ nil
42
+ else
43
+ native_type_cast_from_user(value)
44
+ end
45
+ end
46
+
47
+ def cast_time(value)
48
+ time = nil
49
+ if ActiveRecord::Base.time_zone_aware_attributes
50
+ if value.is_a?(String)
51
+ time = Time.zone.parse(value) rescue nil
52
+ end
53
+ time ||= native_type_cast_from_user(value)
54
+ if time
55
+ if value.is_a?(String) && value !~ /[+\-Z][\d:]*$/
56
+ # time was given without an explicit zone, so assume it was given in Time.zone
57
+ ActiveSupport::TimeWithZone.new(nil, Time.zone, time)
58
+ else
59
+ time.in_time_zone rescue time
60
+ end
61
+ end
62
+ else
63
+ native_type_cast_from_user(value)
64
+ end
65
+ end
66
+
45
67
  module NativeCasters
46
68
 
47
69
  # Adapter for Rails 3.0 - 4.1.
@@ -1,3 +1,3 @@
1
1
  module ActiveType
2
- VERSION = '0.7.1'
2
+ VERSION = '0.7.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-19 00:00:00.000000000 Z
12
+ date: 2017-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler