ziptz 3.0.18 → 5.0.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 +4 -4
- data/LICENSE +1 -1
- data/README.md +3 -3
- data/data/tz.data +0 -0
- data/data/tz.db +0 -0
- data/lib/version.rb +3 -0
- data/lib/ziptz.rb +23 -58
- data/spec/ziptz_spec.rb +21 -25
- data/ziptz.gemspec +5 -2
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f1ff0d267b6ba06ee70a99186cd14f8684744f4fd243f56d9b7150117f26cc0
|
4
|
+
data.tar.gz: 407d339f02d80651adc97150bccb8e85cac844f948f3e9e7c2d348e110dfc20c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4724ab134a22f108612b724339343a16f78bfcdad477f378bf6e30154cdb9e2470a6f95964dbabbbfa874253df215a88e93adba6a0e0bcb8a4bc4f6b88eb2e68
|
7
|
+
data.tar.gz: 69242029d2511543b28068cc0045f4de2ee00b00458a834dbcd810b736d75090f8c1fa74e8156f124a4857059b93d4f6ba15174e75d2340aa458062821a089df
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -6,13 +6,13 @@
|
|
6
6
|
|
7
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>
|
9
|
+
<i>ZIP codes are up to date as of <b>December 2023</b>.</i>
|
10
10
|
|
11
11
|
## Compatibility
|
12
12
|
|
13
13
|
Ziptz is tested to work with the following versions of Ruby:
|
14
14
|
|
15
|
-
* Ruby
|
15
|
+
* Ruby 3.1.x, 3.2.x, 3.3.x
|
16
16
|
|
17
17
|
## Installation
|
18
18
|
|
@@ -160,7 +160,7 @@ Time zone names now reflect standard tz-database names.
|
|
160
160
|
|
161
161
|
## License
|
162
162
|
|
163
|
-
Copyright (c) 2015-
|
163
|
+
Copyright (c) 2015-2024 Keith Morrison <<keithm@infused.org>>
|
164
164
|
|
165
165
|
Permission is hereby granted, free of charge, to any person
|
166
166
|
obtaining a copy of this software and associated documentation
|
data/data/tz.data
CHANGED
Binary file
|
data/data/tz.db
ADDED
Binary file
|
data/lib/version.rb
ADDED
data/lib/ziptz.rb
CHANGED
@@ -1,37 +1,42 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'sqlite3'
|
2
|
+
require 'version'
|
3
3
|
|
4
4
|
class Ziptz
|
5
|
-
VERSION = '3.0.18'.freeze
|
6
|
-
|
7
5
|
def self.instance
|
8
6
|
@instance ||= new
|
9
7
|
end
|
10
8
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
9
|
+
def db
|
10
|
+
@db ||= begin
|
11
|
+
db = SQLite3::Database.open(tz_data_path)
|
12
|
+
db.results_as_hash = true
|
13
|
+
db
|
14
|
+
end
|
15
|
+
end
|
14
16
|
|
15
|
-
|
17
|
+
def time_zone_name(zip)
|
18
|
+
time_zone_info(zip)&.dig('time_zone')
|
16
19
|
end
|
17
20
|
|
18
21
|
def time_zone_offset(zip)
|
19
|
-
|
20
|
-
return unless tz_info
|
21
|
-
|
22
|
-
tzm_info = tzm[tz_info[:tz]]
|
23
|
-
tzm_info[:offset] && tzm_info[:offset].to_i
|
22
|
+
time_zone_info(zip)&.dig('offset')
|
24
23
|
end
|
25
24
|
|
26
25
|
def time_zone_uses_dst?(zip)
|
27
26
|
tz_info = time_zone_info(zip)
|
28
27
|
return unless tz_info
|
29
28
|
|
30
|
-
tz_info[
|
29
|
+
tz_info['observes_dst'] == 1
|
31
30
|
end
|
32
31
|
|
33
32
|
def zips(tz_name)
|
34
|
-
|
33
|
+
sql = <<-SQL
|
34
|
+
select zip_code
|
35
|
+
from zip_codes
|
36
|
+
where time_zone = ?
|
37
|
+
order by zip_code
|
38
|
+
SQL
|
39
|
+
db.execute(sql, tz_name).map { |row| row['zip_code'] }
|
35
40
|
end
|
36
41
|
|
37
42
|
def inspect
|
@@ -40,53 +45,13 @@ class Ziptz
|
|
40
45
|
|
41
46
|
protected
|
42
47
|
|
43
|
-
def tzm
|
44
|
-
@tzm ||= load_tzm_data
|
45
|
-
end
|
46
|
-
|
47
|
-
def lazy_tz
|
48
|
-
@lazy_tz ||= lazy_load_tz_data
|
49
|
-
end
|
50
|
-
|
51
|
-
def tz
|
52
|
-
@tz ||= load_tz_data
|
53
|
-
end
|
54
|
-
|
55
48
|
def time_zone_info(zip)
|
56
|
-
|
57
|
-
_, tz, dst = data.strip.split('|')
|
58
|
-
{tz: tz, dst: dst == '1'}
|
59
|
-
end
|
60
|
-
end
|
49
|
+
return unless zip
|
61
50
|
|
62
|
-
|
63
|
-
File.join(File.dirname(__FILE__), '..', 'data', 'tzm.data')
|
51
|
+
db.get_first_row('select * from zip_codes where zip_code = ? limit 1', zip[0, 5])
|
64
52
|
end
|
65
53
|
|
66
54
|
def tz_data_path
|
67
|
-
File.join(File.dirname(__FILE__), '..', 'data', 'tz.
|
68
|
-
end
|
69
|
-
|
70
|
-
def lazy_load_tz_data
|
71
|
-
uncompressed = Zlib::Inflate.inflate(File.read(tz_data_path, encoding: 'ASCII-8BIT'))
|
72
|
-
uncompressed.each_line.with_object({}) do |line, data|
|
73
|
-
data[line.slice(0, 5)] = line
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def load_tz_data
|
78
|
-
uncompressed = Zlib::Inflate.inflate(File.read(tz_data_path, encoding: 'ASCII-8BIT'))
|
79
|
-
uncompressed.each_line.with_object({}) do |line, data|
|
80
|
-
zip, tz, dst = line.strip.split('|')
|
81
|
-
data[zip] = {tz: tz, dst: dst == '1'}
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def load_tzm_data
|
86
|
-
uncompressed = Zlib::Inflate.inflate(File.read(tzm_data_path, encoding: 'ASCII-8BIT'))
|
87
|
-
uncompressed.each_line.with_object({}) do |line, data|
|
88
|
-
tz, offset = line.strip.split('|')
|
89
|
-
data[tz] = {offset: offset}
|
90
|
-
end
|
55
|
+
File.join(File.dirname(__FILE__), '..', 'data', 'tz.db')
|
91
56
|
end
|
92
57
|
end
|
data/spec/ziptz_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Ziptz do
|
4
|
-
let(:ziptz) {
|
4
|
+
let(:ziptz) { described_class.new }
|
5
5
|
|
6
6
|
describe 'when inspected' do
|
7
7
|
it 'does not show internal instance variables' do
|
@@ -27,39 +27,35 @@ RSpec.describe Ziptz do
|
|
27
27
|
expect(ziptz.time_zone_name('xyz')).to be_nil
|
28
28
|
end
|
29
29
|
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#time_zone_name' do
|
33
|
-
context 'when given a 5-digit zipcode' do
|
34
|
-
it 'returns the time zone number' do
|
35
|
-
expect(ziptz.time_zone_name('97034')).to eq 'America/Los_Angeles'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'when given a 9-digit zipcode' do
|
40
|
-
it 'returns the time zone number' do
|
41
|
-
expect(ziptz.time_zone_name('97034-1234')).to eq 'America/Los_Angeles'
|
42
|
-
end
|
43
|
-
end
|
44
30
|
|
45
|
-
context 'when
|
31
|
+
context 'when nil is passed' do
|
46
32
|
it 'returns nil' do
|
47
|
-
expect(ziptz.time_zone_name(
|
33
|
+
expect(ziptz.time_zone_name(nil)).to be_nil
|
48
34
|
end
|
49
35
|
end
|
50
36
|
end
|
51
37
|
|
52
38
|
describe '#time_zone_uses_dst?' do
|
53
|
-
context 'when given a 5-digit zipcode' do
|
54
|
-
it 'returns
|
39
|
+
context 'when given a valid 5-digit zipcode' do
|
40
|
+
it 'returns true' do
|
55
41
|
expect(ziptz.time_zone_uses_dst?('97034')).to eq true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when given an invalid 5-digit zipcode' do
|
46
|
+
it 'returns false' do
|
56
47
|
expect(ziptz.time_zone_uses_dst?('85004')).to eq false
|
57
48
|
end
|
58
49
|
end
|
59
50
|
|
60
|
-
context 'when given a 9-digit zipcode' do
|
61
|
-
it 'returns a
|
51
|
+
context 'when given a valid 9-digit zipcode' do
|
52
|
+
it 'returns a true' do
|
62
53
|
expect(ziptz.time_zone_uses_dst?('97034-1234')).to eq true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when given an invalid 9-digit zipcode' do
|
58
|
+
it 'returns false' do
|
63
59
|
expect(ziptz.time_zone_uses_dst?('85004-1234')).to eq false
|
64
60
|
end
|
65
61
|
end
|
@@ -74,13 +70,13 @@ RSpec.describe Ziptz do
|
|
74
70
|
describe '#time_zone_offset' do
|
75
71
|
context 'when given a 5-digit zipcode' do
|
76
72
|
it 'returns the time zone number' do
|
77
|
-
expect(ziptz.time_zone_offset('97034')).to eq(-
|
73
|
+
expect(ziptz.time_zone_offset('97034')).to eq(-28_800)
|
78
74
|
end
|
79
75
|
end
|
80
76
|
|
81
77
|
context 'when given a 9-digit zipcode' do
|
82
78
|
it 'returns the time zone number' do
|
83
|
-
expect(ziptz.time_zone_offset('97034-1234')).to eq(-
|
79
|
+
expect(ziptz.time_zone_offset('97034-1234')).to eq(-28_800)
|
84
80
|
end
|
85
81
|
end
|
86
82
|
|
@@ -110,13 +106,13 @@ RSpec.describe Ziptz do
|
|
110
106
|
describe '#instance' do
|
111
107
|
context 'when given a 5 digit zip code' do
|
112
108
|
it 'matches the behavior of Ziptz.new' do
|
113
|
-
expect(
|
109
|
+
expect(described_class.instance.time_zone_name('97034')).to eq ziptz.time_zone_name('97034')
|
114
110
|
end
|
115
111
|
end
|
116
112
|
|
117
113
|
context 'when called twice' do
|
118
114
|
it 'returns identical instances' do
|
119
|
-
expect(
|
115
|
+
expect(described_class.instance.object_id).to eq described_class.instance.object_id
|
120
116
|
end
|
121
117
|
end
|
122
118
|
end
|
data/ziptz.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
6
|
s.name = 'ziptz'
|
@@ -15,6 +17,7 @@ Gem::Specification.new do |s|
|
|
15
17
|
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
16
18
|
s.files = Dir['README.md', 'LICENSE', '{data,lib,spec}/**/*', 'ziptz.gemspec']
|
17
19
|
s.require_paths = ['lib']
|
18
|
-
s.required_ruby_version = '>=
|
20
|
+
s.required_ruby_version = '>= 3.1.0'
|
19
21
|
s.metadata['rubygems_mfa_required'] = 'true'
|
22
|
+
s.add_dependency 'sqlite3', '~> 1.6'
|
20
23
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ziptz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
12
|
-
dependencies:
|
11
|
+
date: 2023-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sqlite3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
13
27
|
description: Get timezone info for all 5-digit US zip codes
|
14
28
|
email: keithm@infused.org
|
15
29
|
executables: []
|
@@ -21,7 +35,9 @@ files:
|
|
21
35
|
- LICENSE
|
22
36
|
- README.md
|
23
37
|
- data/tz.data
|
38
|
+
- data/tz.db
|
24
39
|
- data/tzm.data
|
40
|
+
- lib/version.rb
|
25
41
|
- lib/ziptz.rb
|
26
42
|
- spec/spec_helper.rb
|
27
43
|
- spec/ziptz_spec.rb
|
@@ -40,14 +56,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
56
|
requirements:
|
41
57
|
- - ">="
|
42
58
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
59
|
+
version: 3.1.0
|
44
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
61
|
requirements:
|
46
62
|
- - ">="
|
47
63
|
- !ruby/object:Gem::Version
|
48
64
|
version: '0'
|
49
65
|
requirements: []
|
50
|
-
rubygems_version: 3.
|
66
|
+
rubygems_version: 3.5.3
|
51
67
|
signing_key:
|
52
68
|
specification_version: 4
|
53
69
|
summary: TimeZone info for any 5-digit US zip code
|