timezone 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,2 @@
1
- -631152001:zzz:0:0
1
+ -631152001:-00:0:0
2
2
  2066860801:TFT:0:18000
@@ -25,7 +25,8 @@ module Timezone
25
25
 
26
26
  data = JSON.parse(response.body)
27
27
 
28
- return data['timezoneId'] if data['timezoneId']
28
+ timezone_id = get_timezone_id(data)
29
+ return timezone_id if timezone_id
29
30
 
30
31
  return unless data['status']
31
32
 
@@ -36,6 +37,16 @@ module Timezone
36
37
 
37
38
  private
38
39
 
40
+ def get_timezone_id(data)
41
+ return data['timezoneId'] if data['timezoneId']
42
+
43
+ if config.offset_etc_zones && data['gmtOffset']
44
+ return unless data['gmtOffset'].is_a? Numeric
45
+ return 'Etc/UTC' if data['gmtOffset'] == 0
46
+ "Etc/GMT#{format('%+d', -data['gmtOffset'])}"
47
+ end
48
+ end
49
+
39
50
  def url(lat, long)
40
51
  query = URI.encode_www_form(
41
52
  'lat' => lat,
@@ -7,15 +7,20 @@ module Timezone
7
7
  class Test < ::Timezone::Lookup::Basic
8
8
  def initialize(_config)
9
9
  @stubs = {}
10
+ @default_stub = nil
10
11
  end
11
12
 
12
13
  def stub(lat, long, timezone)
13
14
  @stubs[key(lat, long)] = timezone
14
15
  end
15
16
 
17
+ def default(timezone)
18
+ @default_stub = timezone
19
+ end
20
+
16
21
  def lookup(lat, long)
17
22
  @stubs.fetch(key(lat, long)) do
18
- raise ::Timezone::Error::Test, 'missing stub'
23
+ @default_stub || raise(::Timezone::Error::Test, 'missing stub')
19
24
  end
20
25
  end
21
26
 
@@ -1,4 +1,3 @@
1
1
  module Timezone
2
- # The current gem version.
3
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
4
3
  end
@@ -236,7 +236,7 @@ module Timezone
236
236
 
237
237
  return from if from == to
238
238
 
239
- mid = (from + to) / 2
239
+ mid = (from + to).div(2)
240
240
 
241
241
  if yield(time, private_rules[mid])
242
242
  return mid if mid == 0
@@ -0,0 +1 @@
1
+ {"rawOffset":3,"dstOffset":0,"gmtOffset":3,"lng":40,"lat":89}
@@ -0,0 +1 @@
1
+ {"rawOffset":0,"dstOffset":0,"gmtOffset":0,"lng":0,"lat":0}
@@ -0,0 +1 @@
1
+ {"rawOffset":11.5,"dstOffset":0,"gmtOffset":11.5,"lng":167,"lat":-29}
@@ -0,0 +1 @@
1
+ {"rawOffset":11.5,"dstOffset":0,"gmtOffset":"n/a","lng":167,"lat":-29}
@@ -9,10 +9,19 @@ class TestGeonames < ::Minitest::Test
9
9
  [-34.92771808058, 138.477041423321]
10
10
  end
11
11
 
12
- def lookup
12
+ def etc_data
13
+ {
14
+ arctic: { coordinates: [89, 40], name: 'Etc/GMT-3' },
15
+ atlantic: { coordinates: [0, 0], name: 'Etc/UTC' },
16
+ norfolk: { coordinates: [-29, 167], name: 'Etc/GMT-11' }
17
+ }
18
+ end
19
+
20
+ def lookup(&_block)
13
21
  config = OpenStruct.new
14
22
  config.username = 'timezone'
15
23
  config.request_handler = HTTPTestClient
24
+ yield config if block_given?
16
25
 
17
26
  Timezone::Lookup::Geonames.new(config)
18
27
  end
@@ -35,6 +44,31 @@ class TestGeonames < ::Minitest::Test
35
44
  assert_equal 'Australia/Adelaide', mine.lookup(*coordinates)
36
45
  end
37
46
 
47
+ def test_lookup_with_etc
48
+ etc_data.each do |key, data|
49
+ mine = lookup { |c| c.offset_etc_zones = true }
50
+ mine.client.body = File.open(
51
+ mock_path + "/lat_lon_coords_#{key}.txt"
52
+ ).read
53
+
54
+ assert_equal data[:name], mine.lookup(*data[:coordinates])
55
+ end
56
+ end
57
+
58
+ def test_wrong_offset
59
+ mine = lookup { |c| c.offset_etc_zones = true }
60
+ mine.client.body = File.open(
61
+ mock_path + '/lat_lon_coords_wrong_offset.txt'
62
+ ).read
63
+
64
+ assert_nil mine.lookup(*coordinates)
65
+ end
66
+
67
+ def test_lookup_etc_without_option
68
+ mine = lookup
69
+ assert_nil mine.lookup(*etc_data[:atlantic][:coordinates])
70
+ end
71
+
38
72
  def assert_exception(lookup, message)
39
73
  exception = false
40
74
 
@@ -21,4 +21,11 @@ class TestTest < ::Minitest::Test
21
21
  lookup.lookup(100, 100)
22
22
  end
23
23
  end
24
+
25
+ def test_default_stub
26
+ mine = lookup
27
+ mine.default('America/Toronto')
28
+
29
+ assert_equal 'America/Toronto', mine.lookup(-12, 12)
30
+ end
24
31
  end
@@ -0,0 +1,11 @@
1
+ require 'timezone'
2
+ require 'minitest/autorun'
3
+ require 'mathn'
4
+
5
+ class TestTimezone < ::Minitest::Test
6
+ parallelize_me!
7
+
8
+ def test_lookup_mathn_compatibility
9
+ Timezone['America/Regina'].utc_offset
10
+ end
11
+ end
@@ -3,27 +3,27 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
  require 'timezone/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = 'timezone'
7
- s.version = Timezone::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ['Pan Thomakos']
10
- s.email = ['pan.thomakos@gmail.com']
11
- s.homepage =
12
- "http://github.com/panthomakos/timezone/tree/#{Timezone::VERSION}"
13
- s.summary = "timezone-#{Timezone::VERSION}"
14
- s.license = 'MIT'
6
+ s.name = 'timezone'
7
+ s.version = Timezone::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Pan Thomakos']
10
+ s.email = ['pan.thomakos@gmail.com']
11
+ s.homepage = 'https://github.com/panthomakos/timezone'
12
+ s.summary = "timezone-#{Timezone::VERSION}"
13
+ s.license = 'MIT'
15
14
  s.description = 'Accurate current and historical timezones for Ruby with ' \
16
15
  'support for Geonames and Google latitude - longitude lookups.'
17
16
 
18
17
  s.rubyforge_project = 'timezone'
19
18
 
20
- s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
21
  s.executables = `git ls-files -- bin/*`
23
22
  .split("\n").map { |f| File.basename(f) }
23
+
24
24
  s.extra_rdoc_files = ['README.markdown', 'License.txt']
25
- s.rdoc_options = ['--charset=UTF-8']
26
- s.require_paths = ['lib']
25
+ s.rdoc_options = ['--charset=UTF-8']
26
+ s.require_paths = ['lib']
27
27
 
28
28
  s.add_development_dependency('rake')
29
29
  s.add_development_dependency('minitest', '~> 5.8')
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: 1.0.0
4
+ version: 1.1.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: 2016-05-28 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -698,6 +698,10 @@ files:
698
698
  - test/mocks/invalid_latlong.json
699
699
  - test/mocks/invalid_parameter.json
700
700
  - test/mocks/lat_lon_coords.txt
701
+ - test/mocks/lat_lon_coords_arctic.txt
702
+ - test/mocks/lat_lon_coords_atlantic.txt
703
+ - test/mocks/lat_lon_coords_norfolk.txt
704
+ - test/mocks/lat_lon_coords_wrong_offset.txt
701
705
  - test/test_timezone.rb
702
706
  - test/timezone/lookup/test_basic.rb
703
707
  - test/timezone/lookup/test_geonames.rb
@@ -706,10 +710,11 @@ files:
706
710
  - test/timezone/test_deprecate.rb
707
711
  - test/timezone/test_loader.rb
708
712
  - test/timezone/test_lookup.rb
713
+ - test/timezone/test_mathn_compatibility.rb
709
714
  - test/timezone/test_nil_zone.rb
710
715
  - test/timezone/test_zone.rb
711
716
  - timezone.gemspec
712
- homepage: http://github.com/panthomakos/timezone/tree/1.0.0
717
+ homepage: https://github.com/panthomakos/timezone
713
718
  licenses:
714
719
  - MIT
715
720
  metadata: {}
@@ -733,7 +738,7 @@ rubyforge_project: timezone
733
738
  rubygems_version: 2.4.5.1
734
739
  signing_key:
735
740
  specification_version: 4
736
- summary: timezone-1.0.0
741
+ summary: timezone-1.1.0
737
742
  test_files:
738
743
  - test/data/Helsinki_rules_without_timestamps.json
739
744
  - test/data/asia
@@ -744,6 +749,10 @@ test_files:
744
749
  - test/mocks/invalid_latlong.json
745
750
  - test/mocks/invalid_parameter.json
746
751
  - test/mocks/lat_lon_coords.txt
752
+ - test/mocks/lat_lon_coords_arctic.txt
753
+ - test/mocks/lat_lon_coords_atlantic.txt
754
+ - test/mocks/lat_lon_coords_norfolk.txt
755
+ - test/mocks/lat_lon_coords_wrong_offset.txt
747
756
  - test/test_timezone.rb
748
757
  - test/timezone/lookup/test_basic.rb
749
758
  - test/timezone/lookup/test_geonames.rb
@@ -752,6 +761,7 @@ test_files:
752
761
  - test/timezone/test_deprecate.rb
753
762
  - test/timezone/test_loader.rb
754
763
  - test/timezone/test_lookup.rb
764
+ - test/timezone/test_mathn_compatibility.rb
755
765
  - test/timezone/test_nil_zone.rb
756
766
  - test/timezone/test_zone.rb
757
767
  has_rdoc: