timezone 0.5.0 → 0.6.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/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +107 -41
- data/.travis.yml +3 -4
- data/CHANGES.markdown +4 -1
- data/README.markdown +16 -1
- data/data/America/Cayman +3 -971
- data/data/America/Metlakatla +970 -1
- data/data/America/Santa_Isabel +981 -981
- data/data/Asia/Chita +2 -1
- data/data/Asia/Karachi +2 -2
- data/data/Asia/Tehran +924 -0
- data/data/Iran +924 -0
- data/lib/timezone/active_support.rb +1 -1
- data/lib/timezone/configure.rb +7 -1
- data/lib/timezone/error.rb +1 -0
- data/lib/timezone/lookup/test.rb +29 -0
- data/lib/timezone/parser.rb +2 -2
- data/lib/timezone/version.rb +1 -1
- data/lib/timezone/zone.rb +1 -1
- data/test/test_lookup_test.rb +39 -0
- data/test/timezone_test.rb +7 -3
- metadata +6 -3
data/lib/timezone/configure.rb
CHANGED
@@ -70,7 +70,13 @@ module Timezone
|
|
70
70
|
use_google? && !!google_client_id
|
71
71
|
end
|
72
72
|
|
73
|
+
def self.lookup=(lookup)
|
74
|
+
@lookup = lookup && lookup.new(self)
|
75
|
+
end
|
76
|
+
|
73
77
|
def self.lookup
|
78
|
+
return @lookup if @lookup
|
79
|
+
|
74
80
|
use_google? ? google_lookup : geonames_lookup
|
75
81
|
end
|
76
82
|
|
@@ -99,7 +105,7 @@ module Timezone
|
|
99
105
|
end
|
100
106
|
|
101
107
|
class << self
|
102
|
-
|
108
|
+
alias url= geonames_url=
|
103
109
|
end
|
104
110
|
|
105
111
|
# The Google API URL
|
data/lib/timezone/error.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'timezone/lookup/basic'
|
2
|
+
require 'timezone/error'
|
3
|
+
|
4
|
+
module Timezone
|
5
|
+
module Lookup
|
6
|
+
class Test < ::Timezone::Lookup::Basic
|
7
|
+
def initialize(config)
|
8
|
+
@stubs = {}
|
9
|
+
# Regular config w/ protocol and URL checks does not apply for stubs.
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub(lat, lng, timezone)
|
13
|
+
@stubs[key(lat, lng)] = timezone
|
14
|
+
end
|
15
|
+
|
16
|
+
def lookup(lat, lng)
|
17
|
+
@stubs.fetch(key(lat, lng)) do
|
18
|
+
raise ::Timezone::Error::Test, 'missing stub'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def key(lat, lng)
|
25
|
+
"#{lat},#{lng}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/timezone/parser.rb
CHANGED
@@ -4,7 +4,7 @@ module Timezone
|
|
4
4
|
class Parser
|
5
5
|
LINE = /\s*(.+)\s*=\s*(.+)\s*isdst=(\d+)\s*gmtoff=([\+\-]*\d+)/
|
6
6
|
|
7
|
-
ZONEINFO_DIR = '/usr/share/zoneinfo'
|
7
|
+
ZONEINFO_DIR = '/usr/share/zoneinfo'.freeze
|
8
8
|
|
9
9
|
attr_reader :zoneinfo
|
10
10
|
|
@@ -24,7 +24,7 @@ module Timezone
|
|
24
24
|
class Line
|
25
25
|
attr_accessor :source, :name, :dst, :offset
|
26
26
|
|
27
|
-
SOURCE_FORMAT = '%a %b %e %H:%M:%S %Y %Z'
|
27
|
+
SOURCE_FORMAT = '%a %b %e %H:%M:%S %Y %Z'.freeze
|
28
28
|
|
29
29
|
def initialize(match)
|
30
30
|
self.source = Time.strptime(match[1]+'C', SOURCE_FORMAT).to_i
|
data/lib/timezone/version.rb
CHANGED
data/lib/timezone/zone.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'timezone/configure'
|
2
|
+
require 'timezone/lookup/test'
|
3
|
+
require 'timezone/zone'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
class TestLookupTest < ::Minitest::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
Timezone::Configure.begin do |c|
|
9
|
+
c.lookup = ::Timezone::Lookup::Test
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_simple_stub
|
14
|
+
::Timezone::Configure.lookup.stub(-10, 10, 'America/Los_Angeles')
|
15
|
+
|
16
|
+
assert_equal(
|
17
|
+
'America/Los_Angeles',
|
18
|
+
::Timezone::Zone.new(lat: -10, lon: 10).zone)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_missing_stub
|
22
|
+
assert_raises(::Timezone::Error::Test) do
|
23
|
+
::Timezone::Zone.new(lat: 100, lon: 100)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_clear_lookup
|
28
|
+
::Timezone::Configure.begin do |c|
|
29
|
+
c.username = 'foo'
|
30
|
+
c.lookup = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
assert ::Timezone::Lookup::Geonames, ::Timezone::Configure.lookup.class
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
Timezone::Configure.begin{ |c| c.lookup = nil }
|
38
|
+
end
|
39
|
+
end
|
data/test/timezone_test.rb
CHANGED
@@ -256,7 +256,7 @@ class TimezoneTest < ::Minitest::Unit::TestCase
|
|
256
256
|
:time_with_offset,
|
257
257
|
:dst?,
|
258
258
|
:utc_offset
|
259
|
-
]
|
259
|
+
].freeze
|
260
260
|
|
261
261
|
def check_equivalence(zone, time, other)
|
262
262
|
tz = Timezone::Zone.new(:zone => zone)
|
@@ -279,14 +279,18 @@ class TimezoneTest < ::Minitest::Unit::TestCase
|
|
279
279
|
end
|
280
280
|
|
281
281
|
def test_datetime_equivalence
|
282
|
+
zone = ENV['TZ']
|
283
|
+
ENV['TZ'] = 'UTC'
|
282
284
|
time = Time.new(2011, 2, 3, 13, 5, 0)
|
283
|
-
datetime = DateTime.new(2011, 2, 3, 13, 5, 0)
|
285
|
+
datetime = DateTime.new(2011, 2, 3, 13, 5, 0, 0)
|
284
286
|
|
285
287
|
check_equivalence('America/Los_Angeles', time, datetime)
|
286
288
|
|
287
289
|
time = Time.new(2011, 6, 3, 13, 5, 0)
|
288
|
-
datetime = DateTime.new(2011, 6, 3, 13, 5, 0)
|
290
|
+
datetime = DateTime.new(2011, 6, 3, 13, 5, 0, 0)
|
289
291
|
|
290
292
|
check_equivalence('America/Los_Angeles', time, datetime)
|
293
|
+
ensure
|
294
|
+
ENV['TZ'] = zone
|
291
295
|
end
|
292
296
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timezone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pan Thomakos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -698,6 +698,7 @@ files:
|
|
698
698
|
- lib/timezone/lookup/basic.rb
|
699
699
|
- lib/timezone/lookup/geonames.rb
|
700
700
|
- lib/timezone/lookup/google.rb
|
701
|
+
- lib/timezone/lookup/test.rb
|
701
702
|
- lib/timezone/net_http_client.rb
|
702
703
|
- lib/timezone/parser.rb
|
703
704
|
- lib/timezone/version.rb
|
@@ -712,6 +713,7 @@ files:
|
|
712
713
|
- test/mocks/google_lat_lon_coords.txt
|
713
714
|
- test/mocks/google_request_denied.txt
|
714
715
|
- test/mocks/lat_lon_coords.txt
|
716
|
+
- test/test_lookup_test.rb
|
715
717
|
- test/timezone_test.rb
|
716
718
|
- timezone.gemspec
|
717
719
|
homepage: http://github.com/panthomakos/timezone
|
@@ -738,7 +740,7 @@ rubyforge_project: timezone
|
|
738
740
|
rubygems_version: 2.4.5.1
|
739
741
|
signing_key:
|
740
742
|
specification_version: 4
|
741
|
-
summary: timezone-0.
|
743
|
+
summary: timezone-0.6.0
|
742
744
|
test_files:
|
743
745
|
- test/basic_lookup_test.rb
|
744
746
|
- test/data/Helsinki_rules_without_timestamps.json
|
@@ -750,5 +752,6 @@ test_files:
|
|
750
752
|
- test/mocks/google_lat_lon_coords.txt
|
751
753
|
- test/mocks/google_request_denied.txt
|
752
754
|
- test/mocks/lat_lon_coords.txt
|
755
|
+
- test/test_lookup_test.rb
|
753
756
|
- test/timezone_test.rb
|
754
757
|
has_rdoc:
|