timezone 1.3.25 → 1.3.26

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: ca9a55e18624a9054e44c4af9c58d92ebd85afde7bab843a2e29d39d8d1bcf8e
4
- data.tar.gz: c69a751b73cceafd3d0a0251321c917a6a7be58a3f3a7007fc6a3b43775587bb
3
+ metadata.gz: b58b8ab043d3250736d281e7509b23a4b37d55a8183c774154bfc927a4432435
4
+ data.tar.gz: 34ef3d1d64a98c9089ccc3327eac6b757bc672402d88d764d9bea929419b7376
5
5
  SHA512:
6
- metadata.gz: 2abf338ab752a055d487486026ade95f6875d4fd91dae9548d0dcbf9d0ce36ba7a2f5e5f196dc858cb73d404bead1d155a9b3df6ae456901b29efcdc9e549478
7
- data.tar.gz: da70742fbc31e7a5ea0761fdd150406a1bc2c6d033abfdc9073cac054aacec31e237d5d2f5e3fbbaa6dbda69610b95356200c18e64fd3a5b600bf2f370efff86
6
+ metadata.gz: 14a9ba4a4d102859a3005027a372ad5f2a5e2eaac4497a59b37c4d10fbfd33268a042da306fec8cd74755ded865502f353145806d1104e26c4d9be52dd79076d
7
+ data.tar.gz: dc486e7a84ac0a70e6dd565ad040feefd0d9b708765f93bcb4a0857442564d2bd215258c3999bdbe5b166ce4f06fdb314ed4fc44913081b90cb8a32b789bdfc4
@@ -11,7 +11,7 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
13
  matrix:
14
- ruby-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
14
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3']
15
15
 
16
16
  steps:
17
17
  - uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -1,8 +1,12 @@
1
+ require: rubocop-performance
2
+
1
3
  AllCops:
2
- TargetRubyVersion: 2.2
4
+ TargetRubyVersion: 2.4
5
+ NewCops: enable
6
+ SuggestExtensions: false
3
7
 
4
- Layout/AlignParameters:
5
- EnforcedStyle: with_fixed_indentation
8
+ Gemspec/RequiredRubyVersion:
9
+ Enabled: false
6
10
 
7
11
  Layout/EmptyLineBetweenDefs:
8
12
  Enabled: true
@@ -10,6 +14,9 @@ Layout/EmptyLineBetweenDefs:
10
14
  Layout/MultilineMethodCallIndentation:
11
15
  EnforcedStyle: indented
12
16
 
17
+ Layout/ParameterAlignment:
18
+ EnforcedStyle: with_fixed_indentation
19
+
13
20
  Layout/SpaceAfterComma:
14
21
  Enabled: true
15
22
 
@@ -23,6 +30,9 @@ Layout/SpaceBeforeSemicolon:
23
30
  Enabled: true
24
31
 
25
32
 
33
+ Lint/MissingSuper:
34
+ Enabled: false
35
+
26
36
  Lint/DuplicateMethods:
27
37
  Enabled: true
28
38
 
@@ -39,7 +49,7 @@ Metrics/ClassLength:
39
49
  # Offense count: 13
40
50
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
41
51
  # URISchemes: http, https
42
- Metrics/LineLength:
52
+ Layout/LineLength:
43
53
  Max: 80
44
54
 
45
55
  Metrics/MethodLength:
@@ -85,12 +95,21 @@ Style/NumericLiterals:
85
95
  Style/PreferredHashMethods:
86
96
  Enabled: true
87
97
 
98
+ Style/RedundantArgument:
99
+ Enabled: false
100
+
101
+ Style/RedundantFetchBlock:
102
+ Enabled: false
103
+
88
104
  Style/RedundantReturn:
89
105
  Enabled: true
90
106
 
91
107
  Style/RedundantSelf:
92
108
  Enabled: true
93
109
 
110
+ Style/SafeNavigation:
111
+ Enabled: false
112
+
94
113
  Style/SingleLineMethods:
95
114
  Enabled: false
96
115
 
@@ -103,7 +122,7 @@ Style/StringLiterals:
103
122
  Style/TrivialAccessors:
104
123
  Enabled: true
105
124
 
106
- Style/UnneededPercentQ:
125
+ Style/RedundantPercentQ:
107
126
  Enabled: true
108
127
 
109
128
  Style/DateTime:
data/CHANGES.markdown CHANGED
@@ -1,5 +1,9 @@
1
1
  # master (unreleased)
2
2
 
3
+ # 1.3.26
4
+
5
+ * Fix Rake 13/OpenStruct incompatibility ([@panthomakos][])
6
+
3
7
  # 1.3.25
4
8
 
5
9
  * Updated with `tzdata-2024a` ([@panthomakos][])
@@ -12,16 +12,22 @@ module Timezone
12
12
  module Error
13
13
  # Top-level error. All other timezone errors subclass this one.
14
14
  class Base < StandardError; end
15
+
15
16
  # Indicates an invalid timezone name.
16
17
  class InvalidZone < Base; end
18
+
17
19
  # Indicates a lookup failure.
18
20
  class Lookup < Base; end
21
+
19
22
  # Indicates an error during lookup using the geonames API.
20
23
  class GeoNames < Lookup; end
24
+
21
25
  # Indicates an error during lookup using the google API.
22
26
  class Google < Lookup; end
27
+
23
28
  # Indicates a missing stub during a test lookup.
24
29
  class Test < Lookup; end
30
+
25
31
  # Indicates an invalid configuration.
26
32
  class InvalidConfig < Base; end
27
33
  end
@@ -2,10 +2,10 @@
2
2
 
3
3
  require 'timezone/error'
4
4
 
5
- module Timezone # rubocop:disable Style/Documentation
5
+ module Timezone
6
6
  # Responsible for loading and parsing timezone data from files.
7
7
  module Loader
8
- ZONE_FILE_PATH = File.expand_path(File.dirname(__FILE__) + '/../../data')
8
+ ZONE_FILE_PATH = File.expand_path("#{File.dirname(__FILE__)}/../../data")
9
9
  SOURCE_BIT = 0
10
10
 
11
11
  @rules = {} # cache of loaded rules
@@ -55,6 +55,7 @@ module Timezone
55
55
  return unless data['gmtOffset'].is_a? Numeric
56
56
 
57
57
  return 'Etc/UTC' if data['gmtOffset'].zero?
58
+
58
59
  "Etc/GMT#{format('%+d', -data['gmtOffset'])}"
59
60
  end
60
61
 
@@ -14,7 +14,7 @@ module Timezone
14
14
  class Google < ::Timezone::Lookup::Basic
15
15
  # Indicates that no time zone data could be found for the specified
16
16
  # <lat, lng>. This can occur if the query is incomplete or ambiguous.
17
- NO_TIMEZONE_INFORMATION = 'ZERO_RESULTS'.freeze
17
+ NO_TIMEZONE_INFORMATION = 'ZERO_RESULTS'
18
18
 
19
19
  def initialize(config)
20
20
  if config.api_key.nil?
@@ -34,7 +34,8 @@ module Timezone
34
34
  raise(Timezone::Error::Google, '403 Forbidden')
35
35
  end
36
36
 
37
- return unless response.code =~ /^2\d\d$/
37
+ return unless /^2\d\d$/.match?(response.code)
38
+
38
39
  data = JSON.parse(response.body)
39
40
 
40
41
  return if data['status'] == NO_TIMEZONE_INFORMATION
@@ -4,12 +4,13 @@ require 'timezone/lookup/geonames'
4
4
  require 'timezone/lookup/google'
5
5
  require 'timezone/lookup/test'
6
6
  require 'timezone/net_http_client'
7
+ require 'ostruct'
7
8
 
8
9
  module Timezone
9
10
  # Configure timezone lookups.
10
11
  module Lookup
11
12
  class << self
12
- MISSING_LOOKUP = 'No lookup configured'.freeze
13
+ MISSING_LOOKUP = 'No lookup configured'
13
14
  private_constant :MISSING_LOOKUP
14
15
 
15
16
  # Returns the lookup object
@@ -45,7 +46,7 @@ module Timezone
45
46
  test: ::Timezone::Lookup::Test
46
47
  }.freeze
47
48
 
48
- INVALID_LOOKUP = 'Invalid lookup specified'.freeze
49
+ INVALID_LOOKUP = 'Invalid lookup specified'
49
50
 
50
51
  attr_reader :config
51
52
 
@@ -9,7 +9,7 @@ module Timezone
9
9
  MIN_YEAR = -500
10
10
  MAX_YEAR = 2039
11
11
 
12
- LINE = /\s*(.+)\s*=\s*(.+)\s*isdst=(\d+)\s*gmtoff=([\+\-]*\d+)/
12
+ LINE = /\s*(.+)\s*=\s*(.+)\s*isdst=(\d+)\s*gmtoff=([+\-]*\d+)/.freeze
13
13
 
14
14
  # Bookkeeping files that we do not want to parse.
15
15
  IGNORE = ['leapseconds', 'posixrules', 'tzdata.zi'].freeze
@@ -25,6 +25,7 @@ module Timezone
25
25
  next if File.directory?(file)
26
26
  next if file.end_with?('.tab')
27
27
  next if IGNORE.include?(File.basename(file))
28
+
28
29
  parse(file)
29
30
  end
30
31
  end
@@ -65,7 +66,7 @@ module Timezone
65
66
  def parse_offset(offset)
66
67
  arity = offset.start_with?('-') ? -1 : 1
67
68
 
68
- match = offset.match(/^[\-\+](\d{2})$/)
69
+ match = offset.match(/^[\-+](\d{2})$/)
69
70
  arity * match[1].to_i * 60 * 60
70
71
  end
71
72
  end
@@ -76,10 +77,10 @@ module Timezone
76
77
  class Line
77
78
  attr_accessor :source, :name, :dst, :offset
78
79
 
79
- SOURCE_FORMAT = '%a %b %e %H:%M:%S %Y %Z'.freeze
80
+ SOURCE_FORMAT = '%a %b %e %H:%M:%S %Y %Z'
80
81
 
81
82
  def initialize(match)
82
- self.source = Time.strptime(match[1] + 'C', SOURCE_FORMAT).to_i
83
+ self.source = Time.strptime("#{match[1]}C", SOURCE_FORMAT).to_i
83
84
  self.name = match[2].split(' ').last
84
85
  self.dst = match[3].to_i
85
86
  self.offset = match[4].to_i
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Timezone
4
- VERSION = '1.3.25'.freeze
4
+ VERSION = '1.3.26'
5
5
  end
data/lib/timezone/zone.rb CHANGED
@@ -6,7 +6,6 @@ require 'time'
6
6
 
7
7
  require 'timezone/loader'
8
8
  require 'timezone/error'
9
- require 'timezone/loader'
10
9
 
11
10
  module Timezone
12
11
  # This object represents a real-world timezone. Each instance provides
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'timezone/lookup/geonames'
4
4
  require 'minitest/autorun'
5
+ require 'ostruct'
5
6
  require_relative '../../http_test_client'
6
7
 
7
8
  class TestGeonames < ::Minitest::Test
@@ -19,6 +20,10 @@ class TestGeonames < ::Minitest::Test
19
20
  }
20
21
  end
21
22
 
23
+ def lookup_file(file_name, &block)
24
+ lookup(File.open(File.join(mock_path, file_name)).read, &block)
25
+ end
26
+
22
27
  def lookup(body = nil, &_block)
23
28
  config = OpenStruct.new
24
29
  config.username = 'timezone'
@@ -40,23 +45,25 @@ class TestGeonames < ::Minitest::Test
40
45
  end
41
46
 
42
47
  def test_lookup
43
- mine = lookup(File.open(mock_path + '/lat_lon_coords.txt').read)
48
+ mine = lookup_file('/lat_lon_coords.txt')
44
49
 
45
50
  assert_equal 'Australia/Adelaide', mine.lookup(*coordinates)
46
51
  end
47
52
 
48
53
  def test_lookup_with_etc
49
54
  etc_data.each do |key, data|
50
- body = File.open(mock_path + "/lat_lon_coords_#{key}.txt").read
51
- mine = lookup(body) { |c| c.offset_etc_zones = true }
55
+ mine = lookup_file("/lat_lon_coords_#{key}.txt") do |c|
56
+ c.offset_etc_zones = true
57
+ end
52
58
 
53
59
  assert_equal data[:name], mine.lookup(*data[:coordinates])
54
60
  end
55
61
  end
56
62
 
57
63
  def test_wrong_offset
58
- body = File.open(mock_path + '/lat_lon_coords_wrong_offset.txt').read
59
- mine = lookup(body) { |c| c.offset_etc_zones = true }
64
+ mine = lookup_file('/lat_lon_coords_wrong_offset.txt') do |c|
65
+ c.offset_etc_zones = true
66
+ end
60
67
 
61
68
  assert_nil mine.lookup(*coordinates)
62
69
  end
@@ -80,7 +87,7 @@ class TestGeonames < ::Minitest::Test
80
87
  end
81
88
 
82
89
  def test_api_limit
83
- mine = lookup(File.open(mock_path + '/api_limit_reached.json').read)
90
+ mine = lookup_file('/api_limit_reached.json')
84
91
 
85
92
  assert_exception(
86
93
  mine,
@@ -90,19 +97,19 @@ class TestGeonames < ::Minitest::Test
90
97
  end
91
98
 
92
99
  def test_invalid_latlong
93
- mine = lookup(File.open(mock_path + '/invalid_latlong.json').read)
100
+ mine = lookup_file('/invalid_latlong.json')
94
101
 
95
102
  assert_exception(mine, 'invalid lat/lng')
96
103
  end
97
104
 
98
105
  def test_no_result_found
99
- mine = lookup(File.open(mock_path + '/no_result_found.json').read)
106
+ mine = lookup_file('/no_result_found.json')
100
107
 
101
108
  assert_nil(mine.lookup(10, 10))
102
109
  end
103
110
 
104
111
  def test_invalid_parameter
105
- mine = lookup(File.open(mock_path + '/invalid_parameter.json').read)
112
+ mine = lookup_file('/invalid_parameter.json')
106
113
 
107
114
  assert_exception(mine, 'error parsing parameter')
108
115
  end
@@ -3,6 +3,7 @@
3
3
  require 'timezone/lookup/google'
4
4
  require 'minitest/autorun'
5
5
  require 'timecop'
6
+ require 'ostruct'
6
7
  require_relative '../../http_test_client'
7
8
 
8
9
  class TestGoogle < ::Minitest::Test
@@ -12,6 +13,10 @@ class TestGoogle < ::Minitest::Test
12
13
  [-34.92771808058, 138.477041423321]
13
14
  end
14
15
 
16
+ def lookup_file(file_name, &block)
17
+ lookup(File.open(File.join(mock_path, file_name)).read, &block)
18
+ end
19
+
15
20
  def lookup(body = nil, &_block)
16
21
  config = OpenStruct.new
17
22
  config.api_key = 'MTIzYWJj'
@@ -33,7 +38,7 @@ class TestGoogle < ::Minitest::Test
33
38
  end
34
39
 
35
40
  def test_google_using_lat_long_coordinates
36
- mine = lookup(File.open(mock_path + '/google_lat_lon_coords.txt').read)
41
+ mine = lookup_file('/google_lat_lon_coords.txt')
37
42
 
38
43
  assert_equal 'Australia/Adelaide', mine.lookup(*coordinates)
39
44
  end
@@ -76,7 +81,7 @@ class TestGoogle < ::Minitest::Test
76
81
  end
77
82
 
78
83
  def test_no_result_found
79
- mine = lookup(File.open(mock_path + '/google_no_result_found.json').read)
84
+ mine = lookup_file('/google_no_result_found.json')
80
85
 
81
86
  assert_nil(mine.lookup(26.188703, -78.987053))
82
87
  end
@@ -3,6 +3,7 @@
3
3
  require 'timezone/lookup/test'
4
4
  require 'timezone'
5
5
  require 'minitest/autorun'
6
+ require 'ostruct'
6
7
 
7
8
  class TestTest < ::Minitest::Test
8
9
  parallelize_me!
@@ -8,7 +8,7 @@ class TestLookup < ::Minitest::Test
8
8
  Timezone::Lookup.config(:test)
9
9
 
10
10
  assert_equal Timezone::Lookup::Test,
11
- Timezone::Lookup.lookup.class
11
+ Timezone::Lookup.lookup.class
12
12
  end
13
13
 
14
14
  def test_geonames_config
@@ -17,10 +17,10 @@ class TestLookup < ::Minitest::Test
17
17
  end
18
18
 
19
19
  assert_equal Timezone::Lookup::Geonames,
20
- Timezone::Lookup.lookup.class
20
+ Timezone::Lookup.lookup.class
21
21
 
22
22
  assert_equal Timezone::NetHTTPClient,
23
- Timezone::Lookup.lookup.config.request_handler
23
+ Timezone::Lookup.lookup.config.request_handler
24
24
  end
25
25
 
26
26
  def test_google_config
@@ -29,10 +29,10 @@ class TestLookup < ::Minitest::Test
29
29
  end
30
30
 
31
31
  assert_equal Timezone::Lookup::Google,
32
- Timezone::Lookup.lookup.class
32
+ Timezone::Lookup.lookup.class
33
33
 
34
34
  assert_equal Timezone::NetHTTPClient,
35
- Timezone::Lookup.lookup.config.request_handler
35
+ Timezone::Lookup.lookup.config.request_handler
36
36
  end
37
37
 
38
38
  def test_custom_config
data/timezone.gemspec CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
- # -*- encoding: utf-8 -*-
3
2
 
4
- $:.push File.expand_path('../lib', __FILE__)
3
+ $:.push File.expand_path('lib', __dir__)
5
4
  require 'timezone/version'
6
5
 
7
6
  Gem::Specification.new do |s|
@@ -25,8 +24,11 @@ Gem::Specification.new do |s|
25
24
  s.rdoc_options = ['--charset=UTF-8']
26
25
  s.require_paths = ['lib']
27
26
 
27
+ s.add_runtime_dependency('ostruct', '~> 0.6')
28
+
28
29
  s.add_development_dependency('minitest', '~> 5.8')
29
- s.add_development_dependency('rake', '~> 12')
30
- s.add_development_dependency('rubocop', '= 0.51')
30
+ s.add_development_dependency('rake', '~> 13')
31
+ s.add_development_dependency('rubocop', '= 1.5.1')
32
+ s.add_development_dependency('rubocop-performance', '= 1.5.1')
31
33
  s.add_development_dependency('timecop', '~> 0.8')
32
34
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timezone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.25
4
+ version: 1.3.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pan Thomakos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-12 00:00:00.000000000 Z
11
+ date: 2024-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ostruct
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,28 +44,42 @@ dependencies:
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '12'
47
+ version: '13'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '12'
54
+ version: '13'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rubocop
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - '='
46
60
  - !ruby/object:Gem::Version
47
- version: '0.51'
61
+ version: 1.5.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.5.1
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
80
  - - '='
53
81
  - !ruby/object:Gem::Version
54
- version: '0.51'
82
+ version: 1.5.1
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: timecop
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -751,7 +779,7 @@ requirements: []
751
779
  rubygems_version: 3.4.19
752
780
  signing_key:
753
781
  specification_version: 4
754
- summary: timezone-1.3.25
782
+ summary: timezone-1.3.26
755
783
  test_files:
756
784
  - test/data/Helsinki_rules_without_timestamps.json
757
785
  - test/data/asia