dynamic_time_zone 0.3.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ead0ab82fe327e7498de5548c8dbbb1742a622ffbdf53a7b85a039661fe1ad1f
4
- data.tar.gz: 4e7374119a77057c74cc2d79b2b17de7508bb7d468e2cb27c6c3b006a0411ddb
3
+ metadata.gz: 495fbed668267a932e1719e9877a9450c404baaadc892a5d7c36c8d9fcfef45c
4
+ data.tar.gz: 708f132cbc5da54b49d9793f44f2c03f3c128c66a403d9ecf4f2c6c02f91c5c7
5
5
  SHA512:
6
- metadata.gz: 931a7a54ece7f23763bf211b4f78451ec053bfba94ab42404b3809efe2196628eab8bfcf0aea2ab2ebd8143f57d72366aa42f1e7a1a21c799ce3daf70174792e
7
- data.tar.gz: 39297ddf16cc70ed113dc450a091675e5776e73dff88aaa8289e49f03040d708b9ee3562c124869081cd5ff434201fcfbf2ff58f8e748787a534d7f481d610e3
6
+ metadata.gz: 41c199f3d118993457c9886c25740048a5171392376c32be79707faf12b6cfcd2904475029fc92322c6cb75e84d3e8a2a0564f80e11b5557025698d37d46ff9d
7
+ data.tar.gz: 2235ee587f21a9dd92c64024e7c0cb87cd693fef9705dbda86ed3465c9ea099bb84152a84742ff33e89f7b9f506b320f5227b762c6fc63d47a43aafae5fcf9e1
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TimePatch
4
+ def compare_with_coercion(other)
5
+ if DynamicTimeZone.enabled && other.is_a?(ActiveSupport::TimeWithZone) && other.using_dynamic_time_zone?
6
+ self.utc <=> other.utc
7
+ else
8
+ super
9
+ end
10
+ end
11
+ alias_method :<=>, :compare_with_coercion
12
+ end
13
+
14
+ Time.prepend(TimePatch)
@@ -2,14 +2,22 @@
2
2
 
3
3
  module TimeWithZonePatch
4
4
  def localtime(utc_offset = nil)
5
- return super unless DynamicTimeZone.enabled
5
+ return super unless using_dynamic_time_zone?
6
6
 
7
7
  utc + (utc_offset || 0).seconds
8
8
  end
9
9
  alias_method :getlocal, :localtime
10
10
 
11
11
  def formatted_offset(*args)
12
- DynamicTimeZone.enabled ? '+0000' : super
12
+ actual_formatted_offset = super
13
+ return actual_formatted_offset unless using_dynamic_time_zone?
14
+
15
+ seconds_in_24_hours = 24 * 60 * 60
16
+ utc_offset.abs > seconds_in_24_hours ? '+0000' : actual_formatted_offset
17
+ end
18
+
19
+ def using_dynamic_time_zone?
20
+ DynamicTimeZone::Validator.new.valid?(time_zone.name)
13
21
  end
14
22
  end
15
23
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamicTimeZone
4
- VERSION = '0.3.0'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -21,5 +21,6 @@ require 'dynamic_time_zone/validator'
21
21
  require 'dynamic_time_zone/identifier_builder'
22
22
  require 'dynamic_time_zone/time_zone_data_source'
23
23
  require 'dynamic_time_zone/time_with_zone_patch'
24
+ require 'dynamic_time_zone/time_patch'
24
25
  require 'dynamic_time_zone/offset_format_convertor'
25
26
  require 'dynamic_time_zone/time_parser'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_time_zone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Appfolio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-22 00:00:00.000000000 Z
11
+ date: 2022-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo
@@ -55,6 +55,7 @@ files:
55
55
  - lib/dynamic_time_zone/offset_format_convertor.rb
56
56
  - lib/dynamic_time_zone/test_helper.rb
57
57
  - lib/dynamic_time_zone/time_parser.rb
58
+ - lib/dynamic_time_zone/time_patch.rb
58
59
  - lib/dynamic_time_zone/time_with_zone_patch.rb
59
60
  - lib/dynamic_time_zone/time_zone_data_source.rb
60
61
  - lib/dynamic_time_zone/validator.rb
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  - !ruby/object:Gem::Version
78
79
  version: '0'
79
80
  requirements: []
80
- rubygems_version: 3.0.8
81
+ rubygems_version: 3.0.9
81
82
  signing_key:
82
83
  specification_version: 4
83
84
  summary: Dynamically set the offset from UTC from timezone identifier