ziptz 2.1.11 → 3.0.1

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: 366216ea101a226ef4e1fb3367a2445b21b41a5dd4a06a1732dd0c175c23f580
4
- data.tar.gz: d056db4de8cffcc73ad9469b34781dc60b3017b0ddee651d4f048c79e6fde016
3
+ metadata.gz: e542801fa40a2a225e67c8e7dead718bec94979238e27b64d53578723ce8906e
4
+ data.tar.gz: c720f121c5bd87726882d86348c707108a329fc492985584c8f04e4b76e732be
5
5
  SHA512:
6
- metadata.gz: b9e0e80b825e9b70af78828cd94eef615ecb34c0dca3f66e911896dd4537418d695f92bdc828903cbf18b6c68b7c7365bea798201c94c6459c1947ea743a41bf
7
- data.tar.gz: 2f3919e30ba1f9eb546d620820329a59f81065a2aaba4c851da0271cda90d3110a8b6e4e2dfc27cfd42756622e9bb29e3cdf90dc6172e9ccbcba9dc15260dad5
6
+ metadata.gz: 7f0eafc3c80b0c7074f561f1f291ae40591f4e97996943e7ecbdcb9c3c54e6bf67f79141d5b1c92b8aba0c7dce38bf0d493dff39c1c108393edd1d4e26fa636e
7
+ data.tar.gz: 2cde6491cca2335357f0cab943b5c22b89ffdb38258398d23df891369e0c34f6a6c8a6cc5af6416c808d530ac6e575462bc404c57132677a919fbb97bda2b7fc
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ziptz (2.1.11)
4
+ ziptz (3.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activemodel (6.0.3.3)
10
- activesupport (= 6.0.3.3)
11
- activerecord (6.0.3.3)
12
- activemodel (= 6.0.3.3)
13
- activesupport (= 6.0.3.3)
14
- activesupport (6.0.3.3)
9
+ activemodel (6.0.3.4)
10
+ activesupport (= 6.0.3.4)
11
+ activerecord (6.0.3.4)
12
+ activemodel (= 6.0.3.4)
13
+ activesupport (= 6.0.3.4)
14
+ activesupport (6.0.3.4)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
16
  i18n (>= 0.7, < 2)
17
17
  minitest (~> 5.1)
@@ -55,7 +55,7 @@ GEM
55
55
  nenv (~> 0.1)
56
56
  shellany (~> 0.0)
57
57
  parallel (1.19.2)
58
- parser (2.7.1.5)
58
+ parser (2.7.2.0)
59
59
  ast (~> 2.4.1)
60
60
  pry (0.13.1)
61
61
  coderay (~> 1.1)
@@ -65,39 +65,40 @@ GEM
65
65
  rb-fsevent (0.10.4)
66
66
  rb-inotify (0.10.1)
67
67
  ffi (~> 1.0)
68
- regexp_parser (1.8.1)
69
- reline (0.1.5)
68
+ regexp_parser (1.8.2)
69
+ reline (0.1.7)
70
70
  io-console (~> 0.5)
71
71
  rexml (3.2.4)
72
- rspec (3.9.0)
73
- rspec-core (~> 3.9.0)
74
- rspec-expectations (~> 3.9.0)
75
- rspec-mocks (~> 3.9.0)
76
- rspec-core (3.9.3)
77
- rspec-support (~> 3.9.3)
78
- rspec-expectations (3.9.2)
72
+ rspec (3.10.0)
73
+ rspec-core (~> 3.10.0)
74
+ rspec-expectations (~> 3.10.0)
75
+ rspec-mocks (~> 3.10.0)
76
+ rspec-core (3.10.0)
77
+ rspec-support (~> 3.10.0)
78
+ rspec-expectations (3.10.0)
79
79
  diff-lcs (>= 1.2.0, < 2.0)
80
- rspec-support (~> 3.9.0)
81
- rspec-mocks (3.9.1)
80
+ rspec-support (~> 3.10.0)
81
+ rspec-mocks (3.10.0)
82
82
  diff-lcs (>= 1.2.0, < 2.0)
83
- rspec-support (~> 3.9.0)
84
- rspec-support (3.9.3)
85
- rubocop (0.92.0)
83
+ rspec-support (~> 3.10.0)
84
+ rspec-support (3.10.0)
85
+ rubocop (0.93.1)
86
86
  parallel (~> 1.10)
87
87
  parser (>= 2.7.1.5)
88
88
  rainbow (>= 2.2.2, < 4.0)
89
- regexp_parser (>= 1.7)
89
+ regexp_parser (>= 1.8)
90
90
  rexml
91
- rubocop-ast (>= 0.5.0)
91
+ rubocop-ast (>= 0.6.0)
92
92
  ruby-progressbar (~> 1.7)
93
93
  unicode-display_width (>= 1.4.0, < 2.0)
94
- rubocop-ast (0.7.1)
94
+ rubocop-ast (1.1.0)
95
95
  parser (>= 2.7.1.5)
96
96
  rubocop-performance (1.8.1)
97
97
  rubocop (>= 0.87.0)
98
98
  rubocop-ast (>= 0.4.0)
99
- rubocop-rspec (1.43.2)
99
+ rubocop-rspec (1.44.1)
100
100
  rubocop (~> 0.87)
101
+ rubocop-ast (>= 0.7.1)
101
102
  ruby-progressbar (1.10.1)
102
103
  shellany (0.0.1)
103
104
  thor (1.0.1)
@@ -108,7 +109,7 @@ GEM
108
109
  tzinfo (1.2.7)
109
110
  thread_safe (~> 0.1)
110
111
  unicode-display_width (1.7.0)
111
- zeitwerk (2.4.0)
112
+ zeitwerk (2.4.1)
112
113
 
113
114
  PLATFORMS
114
115
  ruby
@@ -130,4 +131,4 @@ DEPENDENCIES
130
131
  ziptz!
131
132
 
132
133
  BUNDLED WITH
133
- 1.17.3
134
+ 2.1.4
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2020 Keith Morrison <keithm@infused.org>
1
+ Copyright (c) 2015-2021 Keith Morrison <keithm@infused.org>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,12 +1,18 @@
1
1
  # Ziptz
2
2
  [![Version](http://img.shields.io/gem/v/ziptz.svg?style=flat)](https://rubygems.org/gems/ziptz)
3
- [![Build Status](http://img.shields.io/travis/infused/ziptz/master.svg?style=flat)](http://travis-ci.org/infused/ziptz)
3
+ [![Build Status](http://img.shields.io/travis/infused/ziptz/master.svg?style=flat)](http://travis-ci.com/infused/ziptz)
4
4
  [![Total Downloads](https://img.shields.io/gem/dt/ziptz.svg)](https://rubygems.org/gems/ziptz/)
5
5
  [![License](https://img.shields.io/github/license/infused/ziptz.svg)](https://github.com/infused/ziptz)
6
6
 
7
- Get time zone and daylight saving time for any US ZIP code.
7
+ Get time zone, daylight saving time, and base offset for any US ZIP code.
8
8
 
9
- <i>ZIP codes are up to date as of <b>October 2020</b>.</i>
9
+ <i>ZIP codes are up to date as of <b>April 2021</b>.</i>
10
+
11
+ ## Compatibility
12
+
13
+ Ziptz is tested to work with the following versions of Ruby:
14
+
15
+ * Ruby 2.3.x, 2.4.x, 2.5.x, 2.6.x, 2.7.x, 3.0.x, and TruffleRuby
10
16
 
11
17
  ## Installation
12
18
 
@@ -24,7 +30,7 @@ Get the time zone name for any ZIP code:
24
30
 
25
31
  Get the time zone offset for any ZIP code:
26
32
 
27
- z.time_zone_offset('97213') #=> -8
33
+ z.time_zone_offset('97213') #=> -28800
28
34
 
29
35
  <em>Note that offsets do not include daylight saving time.</em>
30
36
 
@@ -34,28 +40,106 @@ Determine if the ZIP code uses Daylight Saving Time:
34
40
 
35
41
  Get all the zip codes in a time zone:
36
42
 
37
- z.zips('Pacific/Pago_Pago') #=> ["96799", "96941", "96942", "96943", "96944"]
43
+ z.zips('Pacific/Chuuk') #=> ["96942", "96943"]
38
44
 
39
45
 
40
46
  ## Supported Time Zones
41
47
 
42
- * "America/Puerto_Rico" UTC -04:00
43
- * "America/New_York" UTC -05:00
44
- * "America/Chicago" UTC -06:00
45
- * "America/Denver" UTC -07:00
46
- * "America/Phoenix" UTC -07:00
47
- * "America/Los_Angeles" UTC -08:00
48
- * "America/Anchorage" UTC -09:00
49
- * "America/Adak" UTC -10:00
50
- * "Pacific/Honolulu" UTC -10:00
51
- * "Pacific/Pago_Pago" UTC -11:00
52
- * "Pacific/Majuro" UTC +12:00
53
- * "Pacific/Guam" UTC +10:00
54
- * "Pacific/Palau" UTC +09:00
55
- * "Pacific/Pohnpei" UTC +11:00
48
+ * America/Adak
49
+ * America/Anchorage
50
+ * America/Boise
51
+ * America/Chicago
52
+ * America/Denver
53
+ * America/Detroit
54
+ * America/Indiana/Indianapolis
55
+ * America/Indiana/Knox
56
+ * America/Indiana/Marengo
57
+ * America/Indiana/Petersburg
58
+ * America/Indiana/Tell_City
59
+ * America/Indiana/Vevay
60
+ * America/Indiana/Vincennes
61
+ * America/Indiana/Winamac
62
+ * America/Juneau
63
+ * America/Kentucky/Louisville
64
+ * America/Kentucky/Monticello
65
+ * America/Los_Angeles
66
+ * America/Menominee
67
+ * America/Metlakatla
68
+ * America/New_York
69
+ * America/Nome
70
+ * America/North_Dakota/Beulah
71
+ * America/North_Dakota/Center
72
+ * America/North_Dakota/New_Salem
73
+ * America/Phoenix
74
+ * America/Puerto_Rico
75
+ * America/Sitka
76
+ * America/St_Thomas
77
+ * America/Yakutat
78
+ * Pacific/Chuuk
79
+ * Pacific/Guam
80
+ * Pacific/Honolulu
81
+ * Pacific/Kosrae
82
+ * Pacific/Kwajalein
83
+ * Pacific/Majuro
84
+ * Pacific/Pago_Pago
85
+ * Pacific/Palau
86
+ * Pacific/Pohnpei
87
+ * Pacific/Saipan
88
+ * Pacific/Wake
56
89
 
57
90
  <em>Note that APO/FPO zip codes will not return a known time zone offset.</em>
58
91
 
92
+ ## Prefer raw data?
93
+
94
+ If you would prefer raw data instead of a gem, see my [ZIP Code Time Zones](https://us-west-2.console.aws.amazon.com/dataexchange/home#/products/prodview-4vcapflqwntdw) product on AWS Data Exchange to subscribe.
95
+
96
+ ## Version 3 breaking changes
97
+
98
+ * APO, DPO, and FPO zip codes are no longer included, because they are non-geographic.
99
+ * Time zone offsets are now specified in seconds instead of hours.
100
+ * Time zone are now more granular. The full list of time zones is:
101
+ * America/Adak
102
+ * America/Anchorage
103
+ * America/Boise
104
+ * America/Chicago
105
+ * America/Denver
106
+ * America/Detroit
107
+ * America/Indiana/Indianapolis
108
+ * America/Indiana/Knox
109
+ * America/Indiana/Marengo
110
+ * America/Indiana/Petersburg
111
+ * America/Indiana/Tell_City
112
+ * America/Indiana/Vevay
113
+ * America/Indiana/Vincennes
114
+ * America/Indiana/Winamac
115
+ * America/Juneau
116
+ * America/Kentucky/Louisville
117
+ * America/Kentucky/Monticello
118
+ * America/Los_Angeles
119
+ * America/Menominee
120
+ * America/Metlakatla
121
+ * America/New_York
122
+ * America/Nome
123
+ * America/North_Dakota/Beulah
124
+ * America/North_Dakota/Center
125
+ * America/North_Dakota/New_Salem
126
+ * America/Phoenix
127
+ * America/Puerto_Rico
128
+ * America/Sitka
129
+ * America/St_Thomas
130
+ * America/Yakutat
131
+ * Pacific/Chuuk
132
+ * Pacific/Guam
133
+ * Pacific/Honolulu
134
+ * Pacific/Kosrae
135
+ * Pacific/Kwajalein
136
+ * Pacific/Majuro
137
+ * Pacific/Pago_Pago
138
+ * Pacific/Palau
139
+ * Pacific/Pohnpei
140
+ * Pacific/Saipan
141
+ * Pacific/Wake
142
+
59
143
  ## Version 2 breaking changes
60
144
 
61
145
  Time zone names now reflect standard tz-database names.
@@ -76,7 +160,7 @@ Time zone names now reflect standard tz-database names.
76
160
 
77
161
  ## License
78
162
 
79
- Copyright (c) 2015-2020 Keith Morrison <<keithm@infused.org>>
163
+ Copyright (c) 2015-2021 Keith Morrison <<keithm@infused.org>>
80
164
 
81
165
  Permission is hereby granted, free of charge, to any person
82
166
  obtaining a copy of this software and associated documentation
data/Rakefile CHANGED
@@ -16,9 +16,3 @@ desc 'Open an irb session preloaded with this library'
16
16
  task :console do
17
17
  sh 'irb -r rubygems -I lib -r ziptz.rb'
18
18
  end
19
-
20
- desc 'Create ziptz db from zipcodes database'
21
- task :create_ziptz do
22
- require 'zip_code'
23
- ZipCode.import
24
- end
data/data/tz.data CHANGED
Binary file
data/data/tzm.data ADDED
@@ -0,0 +1,3 @@
1
+ x�uS]O1|���@������G.b4>]ֺrK{��ע�{�z�(�K���vf��I��\L�A��Q��;�4�R,�0�a�p-T0�LZ� �J����mL���B.=�ۊw�N��{#��.Μ�+kjX佗�[sth�7oW]�'4����u)<�v]���
2
+ ���� 1T���g���y�w�ޒ17(��#̟�� u1����d<n�2d���a3t4�#�����U��UR��e!֕� ����X�2
3
+ ���7���s�-`:���OX���� i������������� �:v�K��Ho �����?�o��R&
data/lib/ziptz.rb CHANGED
@@ -1,41 +1,33 @@
1
1
  require 'yaml'
2
+ require 'zlib'
2
3
 
3
4
  class Ziptz
4
- VERSION = '2.1.11'.freeze
5
-
6
- TZ_INFO = {
7
- '0' => {name: 'APO/FPO (time zone unknown)', offset: 0},
8
- '4' => {name: 'America/Puerto_Rico', offset: -4},
9
- '5' => {name: 'America/New_York', offset: -5},
10
- '6' => {name: 'America/Chicago', offset: -6},
11
- '7' => {name: 'America/Denver', offset: -7},
12
- '8' => {name: 'America/Los_Angeles', offset: -8},
13
- '9' => {name: 'America/Anchorage', offset: -9},
14
- '10' => {name: 'Pacific/Honolulu', offset: -10},
15
- '11' => {name: 'Pacific/Pago_Pago', offset: -11},
16
- '13' => {name: 'Pacific/Majuro', offset: 12},
17
- '14' => {name: 'Pacific/Guam', offset: 10},
18
- '15' => {name: 'Pacific/Palau', offset: 9},
19
- '16' => {name: 'Pacific/Pohnpei', offset: 11},
20
- 'AZ' => {name: 'America/Phoenix', offset: -7},
21
- 'AD' => {name: 'America/Adak', offset: -10}
22
- }.freeze
5
+ VERSION = '3.0.1'.freeze
23
6
 
24
7
  def time_zone_name(zip)
25
- get_time_zone(zip)
8
+ tz_info = time_zone_info(zip)
9
+ return unless tz_info
10
+
11
+ tz_info[:tz]
26
12
  end
27
13
 
28
14
  def time_zone_offset(zip)
29
- tz = time_zone_info(zip)
30
- tz && tz[:offset]
15
+ tz_info = time_zone_info(zip)
16
+ return unless tz_info
17
+
18
+ tzm_info = tzm[tz_info[:tz]]
19
+ tzm_info[:offset] && tzm_info[:offset].to_i
31
20
  end
32
21
 
33
22
  def time_zone_uses_dst?(zip)
34
- dst[zip.to_s.slice(0, 5)]
23
+ tz_info = time_zone_info(zip)
24
+ return unless tz_info
25
+
26
+ tz_info[:dst]
35
27
  end
36
28
 
37
29
  def zips(tz_name)
38
- zips_by_code(tz_name)
30
+ tz.select { |_, v| v[:tz].downcase == tz_name.downcase }.keys
39
31
  end
40
32
 
41
33
  def inspect
@@ -44,24 +36,20 @@ class Ziptz
44
36
 
45
37
  protected
46
38
 
47
- def tz
48
- @tz ||= load_tz_data
49
- end
50
-
51
- def dst
52
- @dst ||= load_dst_data
39
+ def tzm
40
+ @tzm ||= load_tzm_data
53
41
  end
54
42
 
55
- def zips_by_code(tz_code)
56
- tz.select { |_, v| v.match(/#{tz_code}/i) }.keys.sort
43
+ def tz
44
+ @tz ||= load_tz_data
57
45
  end
58
46
 
59
47
  def time_zone_info(zip)
60
- TZ_INFO.values.detect { |v| v[:name] == get_time_zone(zip) }
48
+ tz[zip.to_s.slice(0, 5)]
61
49
  end
62
50
 
63
- def get_time_zone(zip)
64
- tz[zip.to_s.slice(0, 5)]
51
+ def tzm_data_path
52
+ File.join(File.dirname(__FILE__), '..', 'data', 'tzm.data')
65
53
  end
66
54
 
67
55
  def tz_data_path
@@ -69,20 +57,18 @@ class Ziptz
69
57
  end
70
58
 
71
59
  def load_tz_data
72
- File.foreach(tz_data_path).with_object({}) do |line, data|
73
- zip, tz = line.strip.split('=')
74
- data[zip] = tz
60
+ uncompressed = Zlib::Inflate.inflate(File.read(tz_data_path, encoding: 'ASCII-8BIT'))
61
+ uncompressed.each_line.with_object({}) do |line, data|
62
+ zip, tz, dst = line.strip.split(':')
63
+ data[zip] = {tz: tz, dst: dst == '1'}
75
64
  end
76
65
  end
77
66
 
78
- def dst_data_path
79
- File.join(File.dirname(__FILE__), '..', 'data', 'dst.data')
80
- end
81
-
82
- def load_dst_data
83
- File.foreach(dst_data_path).with_object({}) do |line, data|
84
- zip, dst = line.strip.split('=')
85
- data[zip] = dst == '1'
67
+ def load_tzm_data
68
+ uncompressed = Zlib::Inflate.inflate(File.read(tzm_data_path, encoding: 'ASCII-8BIT'))
69
+ uncompressed.each_line.with_object({}) do |line, data|
70
+ tz, offset = line.strip.split(':')
71
+ data[tz] = {offset: offset}
86
72
  end
87
73
  end
88
74
  end
data/spec/ziptz_spec.rb CHANGED
@@ -74,13 +74,13 @@ RSpec.describe Ziptz do
74
74
  describe '#time_zone_offset' do
75
75
  context 'when given a 5-digit zipcode' do
76
76
  it 'returns the time zone number' do
77
- expect(ziptz.time_zone_offset('97034')).to eq(-8)
77
+ expect(ziptz.time_zone_offset('97034')).to eq(-28800)
78
78
  end
79
79
  end
80
80
 
81
81
  context 'when given a 9-digit zipcode' do
82
82
  it 'returns the time zone number' do
83
- expect(ziptz.time_zone_offset('97034-1234')).to eq(-8)
83
+ expect(ziptz.time_zone_offset('97034-1234')).to eq(-28800)
84
84
  end
85
85
  end
86
86
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ziptz
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.11
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-01 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Get timezone info for all 5-digit US zip codes
14
14
  email: keithm@infused.org
@@ -25,10 +25,9 @@ files:
25
25
  - LICENSE
26
26
  - README.md
27
27
  - Rakefile
28
- - data/dst.data
29
28
  - data/tz.data
29
+ - data/tzm.data
30
30
  - database.yml
31
- - lib/zip_code.rb
32
31
  - lib/ziptz.rb
33
32
  - spec/spec_helper.rb
34
33
  - spec/ziptz_spec.rb
@@ -53,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
54
  requirements: []
56
- rubygems_version: 3.0.6
55
+ rubygems_version: 3.1.4
57
56
  signing_key:
58
57
  specification_version: 4
59
58
  summary: TimeZone info for any 5-digit US zip code