ensurance 0.1.18 → 0.1.19

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: b49b4eceae00a06f27f9a026ebe7d31f9fed4f09bda541e9e83461b8dedc3c53
4
- data.tar.gz: 40136f447598dcdb7b201c0f4210231c2a8e20251fef70091f351c389a8d5038
3
+ metadata.gz: 1ac8c082d86cf0bde5f2b23ca40b89cce7a4641ed8f57778c79a1a848a02ab82
4
+ data.tar.gz: 1bd231f16ab432a4c5c66058e9f9dde2fa532329863ca92e1b1778b80cfc3466
5
5
  SHA512:
6
- metadata.gz: 7e88bbe03f5ce2a8c7731f381b78f6ebd496d43fdfaa280caaa41e11fcd5ff6ec9ba2c36d8276d7f2391f66a21e388d7142826f99fac8980e771216d39046a6f
7
- data.tar.gz: cc61a40b1e72c773608430df225092c9e44c767c3294fdcad7c8f76c0b1fc112a00638534a0f2aa94bb37d1377a0bd886188aee22abb008fb104e1545e878d4d
6
+ metadata.gz: ab06cec4700be175341d53d82d879056984502327b83d76414d36ed85aa0a1bb49b2051c82cb9c847fa8227a4b156483b0e989d82743300a86d5e98205dbe46b
7
+ data.tar.gz: 3874f44a84344ccb8de3fcef1153bd4ffa259b2d8f8b9ac3c1665e147d307de020e55341d5edacf632f02ab039322502f0c2eb7a816da7036cdc08b461a315cb
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+
3
+ ## 1.0.19
4
+ - always use Time.zone when ensure times or dates
@@ -1,30 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ensurance (0.1.13)
4
+ ensurance (0.1.18)
5
5
  activesupport (>= 3, < 6)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (5.2.1)
11
- activesupport (= 5.2.1)
12
- activerecord (5.2.1)
13
- activemodel (= 5.2.1)
14
- activesupport (= 5.2.1)
10
+ activemodel (5.2.2)
11
+ activesupport (= 5.2.2)
12
+ activerecord (5.2.2)
13
+ activemodel (= 5.2.2)
14
+ activesupport (= 5.2.2)
15
15
  arel (>= 9.0)
16
- activesupport (5.2.1)
16
+ activesupport (5.2.2)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
18
  i18n (>= 0.7, < 2)
19
19
  minitest (~> 5.1)
20
20
  tzinfo (~> 1.1)
21
21
  arel (9.0.0)
22
22
  awesome_print (1.8.0)
23
- concurrent-ruby (1.0.5)
23
+ concurrent-ruby (1.1.4)
24
24
  diff-lcs (1.3)
25
- globalid (0.4.1)
25
+ globalid (0.4.2)
26
26
  activesupport (>= 4.2.0)
27
- i18n (1.1.0)
27
+ i18n (1.5.2)
28
28
  concurrent-ruby (~> 1.0)
29
29
  minitest (5.11.3)
30
30
  rake (10.5.0)
@@ -34,7 +34,7 @@ GEM
34
34
  rspec-mocks (~> 3.8.0)
35
35
  rspec-core (3.8.0)
36
36
  rspec-support (~> 3.8.0)
37
- rspec-expectations (3.8.1)
37
+ rspec-expectations (3.8.2)
38
38
  diff-lcs (>= 1.2.0, < 2.0)
39
39
  rspec-support (~> 3.8.0)
40
40
  rspec-mocks (3.8.0)
@@ -60,4 +60,4 @@ DEPENDENCIES
60
60
  sqlite3 (>= 1.3.0, < 4)
61
61
 
62
62
  BUNDLED WITH
63
- 1.16.2
63
+ 1.17.3
@@ -1,6 +1,7 @@
1
1
  # NOTE: https://blog.daveallie.com/clean-monkey-patching/
2
2
 
3
3
  require 'active_support/core_ext/date'
4
+ require 'active_support/core_ext/time'
4
5
 
5
6
  module Ensurance
6
7
  module DateEnsure
@@ -11,6 +12,8 @@ module Ensurance
11
12
  module ClassMethods
12
13
  DATE_ENSURE_FORMATS = %w[%m/%d/%Y %Y/%m/%d].freeze
13
14
  def ensure(thing)
15
+ Time.zone ||= 'UTC'
16
+
14
17
  case thing.class.name
15
18
  when 'NilClass'
16
19
  nil
@@ -20,9 +23,9 @@ module Ensurance
20
23
  thing
21
24
  when 'String'
22
25
  if thing.to_i.to_s == thing
23
- ::Time.at(thing.to_i).to_date
26
+ ::Time.zone.at(thing.to_i).to_date
24
27
  elsif thing.to_f.to_s == thing
25
- ::Time.at(thing.to_f).to_date
28
+ ::Time.zone.at(thing.to_f).to_date
26
29
  elsif thing.index('/')
27
30
  # Assume US Date format
28
31
  result = nil
@@ -36,7 +39,7 @@ module Ensurance
36
39
  raise ArgumentError, "Bad Date: #{thing}".yellow unless result
37
40
  result
38
41
  else
39
- ::Date.parse(thing)
42
+ ::Time.zone.parse(thing).to_date
40
43
  end
41
44
  else
42
45
  if thing.respond_to?(:to_date)
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/time'
2
+ require 'active_support/time_with_zone'
2
3
 
3
4
  # NOTE: https://blog.daveallie.com/clean-monkey-patching/
4
5
 
@@ -10,6 +11,8 @@ module Ensurance
10
11
 
11
12
  module ClassMethods
12
13
  def ensure(thing)
14
+ ::Time.zone ||= "UTC"
15
+
13
16
  case thing.class.name
14
17
  when 'NilClass'
15
18
  thing
@@ -18,14 +21,14 @@ module Ensurance
18
21
  when 'Date'
19
22
  thing.beginning_of_day
20
23
  when 'Integer', 'Float'
21
- ::Time.at(thing)
24
+ ::Time.zone.at(thing)
22
25
  when 'String'
23
26
  if thing.to_i.to_s == thing
24
- ::Time.at(thing.to_i)
27
+ ::Time.zone.at(thing.to_i)
25
28
  elsif thing.to_f.to_s == thing
26
- ::Time.at(thing.to_f)
29
+ ::Time.zone.at(thing.to_f)
27
30
  else
28
- ::Time.parse(thing)
31
+ ::Time.zone.parse(thing)
29
32
  end
30
33
  else
31
34
  if thing.respond_to?(:to_time)
@@ -1,3 +1,3 @@
1
1
  module Ensurance
2
- VERSION = '0.1.18'.freeze
2
+ VERSION = '0.1.19'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ensurance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Sharpe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-14 00:00:00.000000000 Z
11
+ date: 2019-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -162,6 +162,7 @@ files:
162
162
  - ".gitignore"
163
163
  - ".rspec"
164
164
  - ".travis.yml"
165
+ - CHANGELOG.md
165
166
  - Gemfile
166
167
  - Gemfile.lock
167
168
  - LICENSE.txt