timezone 0.99.2 → 1.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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.markdown +6 -0
  3. data/README.markdown +1 -11
  4. data/Rakefile +3 -1
  5. data/data/America/Caracas +2 -1
  6. data/data/Asia/Almaty +51 -48
  7. data/data/Asia/Anadyr +3 -3
  8. data/data/Asia/Aqtau +50 -50
  9. data/data/Asia/Aqtobe +51 -49
  10. data/data/Asia/Baku +2 -2
  11. data/data/Asia/Barnaul +3 -3
  12. data/data/Asia/Chita +3 -3
  13. data/data/Asia/Irkutsk +3 -3
  14. data/data/Asia/Kamchatka +3 -3
  15. data/data/Asia/Khandyga +3 -3
  16. data/data/Asia/Krasnoyarsk +3 -3
  17. data/data/Asia/Magadan +5 -4
  18. data/data/Asia/Novokuznetsk +3 -3
  19. data/data/Asia/Novosibirsk +3 -3
  20. data/data/Asia/Omsk +3 -3
  21. data/data/Asia/Oral +51 -50
  22. data/data/Asia/Qyzylorda +51 -50
  23. data/data/Asia/Sakhalin +3 -3
  24. data/data/Asia/Srednekolymsk +3 -3
  25. data/data/Asia/Tomsk +68 -0
  26. data/data/Asia/Ust-Nera +3 -3
  27. data/data/Asia/Vladivostok +3 -3
  28. data/data/Asia/Yakutsk +3 -3
  29. data/data/Asia/Yekaterinburg +3 -3
  30. data/data/Asia/Yerevan +3 -3
  31. data/data/Europe/Astrakhan +2 -2
  32. data/data/Europe/Kaliningrad +3 -3
  33. data/data/Europe/Kirov +64 -0
  34. data/data/Europe/Minsk +2 -2
  35. data/data/Europe/Moscow +3 -3
  36. data/data/Europe/Samara +3 -3
  37. data/data/Europe/Ulyanovsk +3 -3
  38. data/data/Europe/Volgograd +2 -2
  39. data/data/W-SU +3 -3
  40. data/lib/timezone/error.rb +0 -4
  41. data/lib/timezone/lookup/basic.rb +1 -7
  42. data/lib/timezone/lookup/geonames.rb +7 -6
  43. data/lib/timezone/lookup/google.rb +2 -1
  44. data/lib/timezone/net_http_client.rb +1 -10
  45. data/lib/timezone/version.rb +1 -1
  46. data/lib/timezone/zone.rb +1 -122
  47. data/test/http_test_client.rb +1 -2
  48. data/test/mocks/{api_limit_reached.txt → api_limit_reached.json} +0 -0
  49. data/test/mocks/invalid_latlong.json +1 -0
  50. data/test/mocks/invalid_parameter.json +1 -0
  51. data/test/{basic_lookup_test.rb → timezone/lookup/test_basic.rb} +3 -1
  52. data/test/timezone/lookup/test_geonames.rb +33 -4
  53. data/test/timezone/test_zone.rb +211 -3
  54. data/timezone.gemspec +14 -13
  55. metadata +22 -26
  56. data/lib/timezone/active_support.rb +0 -156
  57. data/lib/timezone/configure.rb +0 -258
  58. data/test/geonames_lookup_test.rb +0 -56
  59. data/test/google_lookup_test.rb +0 -81
  60. data/test/test_lookup_test.rb +0 -41
  61. data/test/timezone_test.rb +0 -297
@@ -22,8 +22,8 @@
22
22
  16329600:+04:1:14400
23
23
  15724800:+03:0:10800
24
24
  31446000:+04:0:14400
25
- 15714000:+04:1:14400
26
- 15739200:+03:0:10800
25
+ 15728400:+04:1:14400
26
+ 15724800:+03:0:10800
27
27
  15724800:+04:1:14400
28
28
  15724800:+03:0:10800
29
29
  15724800:+04:1:14400
@@ -37,9 +37,9 @@
37
37
  16329600:EEST:1:10800
38
38
  15724800:EET:0:7200
39
39
  15724800:EEST:1:10800
40
- 15714000:EET:0:7200
41
- 15721200:EEST:1:10800
42
- 15739200:EET:0:7200
40
+ 15724800:EET:0:7200
41
+ 15724800:EEST:1:10800
42
+ 15724800:EET:0:7200
43
43
  15724800:EEST:1:10800
44
44
  15724800:EET:0:7200
45
45
  15724800:EEST:1:10800
@@ -0,0 +1,64 @@
1
+ -1593825529:LMT:0:11928
2
+ 346285128:+03:0:10800
3
+ 1602457200:+04:0:14400
4
+ 15807600:+05:1:18000
5
+ 15728400:+04:0:14400
6
+ 15807600:+05:1:18000
7
+ 15728400:+04:0:14400
8
+ 15807600:+05:1:18000
9
+ 15814800:+04:0:14400
10
+ 15732000:+05:1:18000
11
+ 15724800:+04:0:14400
12
+ 15724800:+05:1:18000
13
+ 15724800:+04:0:14400
14
+ 15724800:+05:1:18000
15
+ 15724800:+04:0:14400
16
+ 15724800:+05:1:18000
17
+ 15724800:+04:0:14400
18
+ 15724800:+05:1:18000
19
+ 15724800:+04:0:14400
20
+ 15728400:+04:1:14400
21
+ 15724800:+03:0:10800
22
+ 16329600:+04:1:14400
23
+ 15724800:+03:0:10800
24
+ 31446000:+04:0:14400
25
+ 15728400:+04:1:14400
26
+ 15724800:+03:0:10800
27
+ 15724800:+04:1:14400
28
+ 15724800:+03:0:10800
29
+ 15724800:+04:1:14400
30
+ 15724800:+03:0:10800
31
+ 15724800:+04:1:14400
32
+ 16329600:+03:0:10800
33
+ 18144000:+04:1:14400
34
+ 13305600:+03:0:10800
35
+ 18144000:+04:1:14400
36
+ 13305600:+03:0:10800
37
+ 18144000:+04:1:14400
38
+ 13305600:+03:0:10800
39
+ 18748800:+04:1:14400
40
+ 12700800:+03:0:10800
41
+ 18748800:+04:1:14400
42
+ 12700800:+03:0:10800
43
+ 18748800:+04:1:14400
44
+ 13305600:+03:0:10800
45
+ 18144000:+04:1:14400
46
+ 13305600:+03:0:10800
47
+ 18144000:+04:1:14400
48
+ 13305600:+03:0:10800
49
+ 18748800:+04:1:14400
50
+ 12700800:+03:0:10800
51
+ 18748800:+04:1:14400
52
+ 12700800:+03:0:10800
53
+ 18748800:+04:1:14400
54
+ 12700800:+03:0:10800
55
+ 18748800:+04:1:14400
56
+ 13305600:+03:0:10800
57
+ 18144000:+04:1:14400
58
+ 13305600:+03:0:10800
59
+ 18144000:+04:1:14400
60
+ 13305600:+03:0:10800
61
+ 18748800:+04:1:14400
62
+ 12700800:+03:0:10800
63
+ 113094000:+04:0:14400
64
+ 21434401:+03:0:10800
@@ -28,8 +28,8 @@
28
28
  47779200:MSK:0:10800
29
29
  15728400:EEST:1:10800
30
30
  15717600:EET:0:7200
31
- 15724800:EEST:1:10800
32
- 15732000:EET:0:7200
31
+ 15732000:EEST:1:10800
32
+ 15724800:EET:0:7200
33
33
  15724800:EEST:1:10800
34
34
  15724800:EET:0:7200
35
35
  15724800:EEST:1:10800
@@ -36,9 +36,9 @@
36
36
  15724800:MSK:0:10800
37
37
  15728400:EEST:1:10800
38
38
  9676800:EET:0:7200
39
- 6033600:MSK:0:10800
40
- 15721200:MSD:1:14400
41
- 15739200:MSK:0:10800
39
+ 6044400:MSK:0:10800
40
+ 15724800:MSD:1:14400
41
+ 15724800:MSK:0:10800
42
42
  15724800:MSD:1:14400
43
43
  15724800:MSK:0:10800
44
44
  15724800:MSD:1:14400
@@ -24,9 +24,9 @@
24
24
  15724800:MSK:0:10800
25
25
  15728400:EEST:1:10800
26
26
  1814400:SAMT:0:10800
27
- 13892400:SAMT:0:14400
28
- 15721200:SAMST:1:18000
29
- 15739200:SAMT:0:14400
27
+ 13903200:SAMT:0:14400
28
+ 15724800:SAMST:1:18000
29
+ 15724800:SAMT:0:14400
30
30
  15724800:SAMST:1:18000
31
31
  15724800:SAMT:0:14400
32
32
  15724800:SAMST:1:18000
@@ -23,9 +23,9 @@
23
23
  15724800:+03:0:10800
24
24
  15728400:+03:1:10800
25
25
  9676800:+02:0:7200
26
- 6033600:+03:0:10800
27
- 15721200:+04:1:14400
28
- 15739200:+03:0:10800
26
+ 6044400:+03:0:10800
27
+ 15724800:+04:1:14400
28
+ 15724800:+03:0:10800
29
29
  15724800:+04:1:14400
30
30
  15724800:+03:0:10800
31
31
  15724800:+04:1:14400
@@ -24,8 +24,8 @@
24
24
  16329600:VOLST:1:14400
25
25
  15724800:VOLT:0:10800
26
26
  31446000:VOLT:0:14400
27
- 15714000:MSD:1:14400
28
- 15739200:MSK:0:10800
27
+ 15728400:MSD:1:14400
28
+ 15724800:MSK:0:10800
29
29
  15724800:MSD:1:14400
30
30
  15724800:MSK:0:10800
31
31
  15724800:MSD:1:14400
data/data/W-SU CHANGED
@@ -36,9 +36,9 @@
36
36
  15724800:MSK:0:10800
37
37
  15728400:EEST:1:10800
38
38
  9676800:EET:0:7200
39
- 6033600:MSK:0:10800
40
- 15721200:MSD:1:14400
41
- 15739200:MSK:0:10800
39
+ 6044400:MSK:0:10800
40
+ 15724800:MSD:1:14400
41
+ 15724800:MSK:0:10800
42
42
  15724800:MSD:1:14400
43
43
  15724800:MSK:0:10800
44
44
  15724800:MSD:1:14400
@@ -12,16 +12,12 @@ module Timezone
12
12
  class Base < StandardError; end
13
13
  # Indicates an invalid timezone name.
14
14
  class InvalidZone < Base; end
15
- # @deprecated this class will be removed in the next release of the gem.
16
- class NilZone < Base; end
17
15
  # Indicates a lookup failure.
18
16
  class Lookup < Base; end
19
17
  # Indicates an error during lookup using the geonames API.
20
18
  class GeoNames < Lookup; end
21
19
  # Indicates an error during lookup using the google API.
22
20
  class Google < Lookup; end
23
- # @deprecated this class will be removed in the next release of the gem.
24
- class ParseTime < Base; end
25
21
  # Indicates a missing stub during a test lookup.
26
22
  class Test < Lookup; end
27
23
  # Indicates an invalid configuration.
@@ -25,13 +25,7 @@ module Timezone
25
25
  #
26
26
  # @return [#get] an instance of a request handler
27
27
  def client
28
- # TODO: Remove http_client once on 1.0.0
29
- @client ||=
30
- if !config.request_handler.nil?
31
- config.request_handler.new(config)
32
- else
33
- config.http_client.new(config.protocol, config.url)
34
- end
28
+ @client ||= config.request_handler.new(config)
35
29
  end
36
30
 
37
31
  # Returns a timezone name for a given lat, long pair.
@@ -21,15 +21,15 @@ module Timezone
21
21
  def lookup(lat, long)
22
22
  response = client.get(url(lat, long))
23
23
 
24
- return unless response.code =~ /^2\d\d$/
24
+ return unless response.body
25
25
 
26
26
  data = JSON.parse(response.body)
27
27
 
28
- if data['status'] && data['status']['value'] == 18
29
- raise(Timezone::Error::GeoNames, 'api limit reached')
30
- end
28
+ return data['timezoneId'] if data['timezoneId']
29
+
30
+ return unless data['status']
31
31
 
32
- data['timezoneId']
32
+ raise(Timezone::Error::GeoNames, data['status']['message'])
33
33
  rescue => e
34
34
  raise(Timezone::Error::GeoNames, e.message)
35
35
  end
@@ -40,7 +40,8 @@ module Timezone
40
40
  query = URI.encode_www_form(
41
41
  'lat' => lat,
42
42
  'lng' => long,
43
- 'username' => config.username)
43
+ 'username' => config.username
44
+ )
44
45
  "/timezoneJSON?#{query}"
45
46
  end
46
47
  end
@@ -64,7 +64,8 @@ module Timezone
64
64
  def url(lat, long)
65
65
  query = URI.encode_www_form(
66
66
  'location' => "#{lat},#{long}",
67
- 'timestamp' => Time.now.to_i)
67
+ 'timestamp' => Time.now.to_i
68
+ )
68
69
 
69
70
  authorize("/maps/api/timezone/json?#{query}")
70
71
  end
@@ -15,16 +15,7 @@ module Timezone
15
15
  # end
16
16
  #
17
17
  class NetHTTPClient
18
- def initialize(protocol, url = nil)
19
- # TODO: Remove once on 1.0.0 #initialize(config)
20
- config = protocol
21
-
22
- if url
23
- config = OpenStruct.new
24
- config.protocol = protocol
25
- config.url = url
26
- end
27
-
18
+ def initialize(config)
28
19
  uri = URI.parse("#{config.protocol}://#{config.url}")
29
20
  @http = Net::HTTP.new(uri.host, uri.port)
30
21
  @http.open_timeout = config.open_timeout || 5
@@ -1,4 +1,4 @@
1
1
  module Timezone
2
2
  # The current gem version.
3
- VERSION = '0.99.2'.freeze
3
+ VERSION = '1.0.0'.freeze
4
4
  end
@@ -4,10 +4,7 @@ require 'time'
4
4
 
5
5
  require 'timezone/loader'
6
6
  require 'timezone/error'
7
- require 'timezone/configure'
8
- require 'timezone/active_support'
9
7
  require 'timezone/loader'
10
- require 'timezone/deprecate'
11
8
 
12
9
  module Timezone
13
10
  # This object represents a real-world timezone. Each instance provides
@@ -47,77 +44,7 @@ module Timezone
47
44
  # @param name [String] the timezone name
48
45
  # @return [Timezone::Zone]
49
46
  def initialize(name)
50
- if name.is_a?(Hash)
51
- legacy_initialize(name)
52
- else
53
- @name = name
54
- end
55
- end
56
-
57
- # @deprecated This method will be replaced with `Zone#name` in
58
- # future versions of this gem.
59
- def zone
60
- Deprecate.call(
61
- self.class,
62
- :zone,
63
- '[DEPRECATED] `Zone#zone` will not be available in ' \
64
- 'the next release of the `timezone` gem. Use `Zone#name` ' \
65
- 'instead.'.freeze
66
- )
67
-
68
- name
69
- end
70
-
71
- # @deprecated This method will be removed in the next release.
72
- def rules
73
- Deprecate.call(
74
- self.class,
75
- :rules,
76
- '[DEPRECATED] `Zone#rules` will not be available in ' \
77
- 'the next release of the `timezone` gem.'.freeze
78
- )
79
-
80
- private_rules
81
- end
82
-
83
- # @deprecated This functionality only exists for migration purposes.
84
- def legacy_initialize(options)
85
- Deprecate.call(
86
- self.class,
87
- :initialize,
88
- '[DEPRECATED] Creating Zone objects using an options hash ' \
89
- 'will be deprecated in the next release of the `timezone` ' \
90
- 'gem. Use `Timezone::[]`, `Timezone::fetch` or ' \
91
- '`Timezone::lookup` instead.'.freeze
92
- )
93
-
94
- if options.key?(:lat) && options.key?(:lon)
95
- options[:zone] = timezone_id options[:lat], options[:lon]
96
- elsif options.key?(:latlon)
97
- options[:zone] = timezone_id(*options[:latlon])
98
- end
99
-
100
- if options[:zone].nil?
101
- raise Timezone::Error::NilZone,
102
- 'No zone was found. Please specify a zone.'.freeze
103
- end
104
-
105
- @name = options[:zone]
106
- private_rules
107
- end
108
-
109
- # @deprecated This functionality will be removed in the next release.
110
- def active_support_time_zone
111
- Deprecate.call(
112
- self.class,
113
- :active_support_time_zone,
114
- '[DEPRECATED] `Zone#active_support_time_zone` will be ' \
115
- 'deprecated in the next release of the `timezone` gem. There ' \
116
- 'will be no replacement.'.freeze
117
- )
118
-
119
- @active_support_time_zone ||=
120
- Timezone::ActiveSupport.format(name, :internal)
47
+ @name = name
121
48
  end
122
49
 
123
50
  # Converts the given time to the local timezone and does not include
@@ -229,50 +156,6 @@ module Timezone
229
156
  utc_offset <=> other.utc_offset
230
157
  end
231
158
 
232
- class << self
233
- # @deprecated This method will be replaced with `Timezone.names`
234
- # in future versions of this gem.
235
- def names
236
- Deprecate.call(
237
- self,
238
- :names,
239
- '[DEPRECATED] `::Timezone::Zone.names` will be removed in ' \
240
- 'the next gem release. Use `::Timezone.names` instead.'.freeze
241
- )
242
-
243
- Loader.names
244
- end
245
-
246
- # @deprecated This functionality will be removed in the next release.
247
- def list(*args)
248
- Deprecate.call(
249
- self,
250
- :list,
251
- '[DEPRECATED] `Zone::list` will be deprecated in the ' \
252
- 'next release of the `timezone` gem. There will be no ' \
253
- 'replacement.'.freeze
254
- )
255
-
256
- args = nil if args.empty? # set to nil if no args are provided
257
- zones = args || Configure.default_for_list || names
258
- list = names.select { |name| zones.include? name }
259
-
260
- @zones = []
261
- now = Time.now
262
- list.each do |name|
263
- item = new(name)
264
- @zones << {
265
- zone: item.name,
266
- title: Configure.replacements[item.name] || item.name,
267
- offset: item.utc_offset,
268
- utc_offset: (item.utc_offset / (60 * 60)),
269
- dst: item.dst?(now)
270
- }
271
- end
272
- @zones.sort_by! { |zone| zone[Configure.order_list_by] }
273
- end
274
- end
275
-
276
159
  private
277
160
 
278
161
  def private_rules
@@ -365,9 +248,5 @@ module Timezone
365
248
  return binary_search(time, mid + 1, to, &block)
366
249
  end
367
250
  end
368
-
369
- def timezone_id(lat, lon)
370
- Timezone::Configure.lookup.lookup(lat, lon)
371
- end
372
251
  end
373
252
  end
@@ -5,8 +5,7 @@ class HTTPTestClient
5
5
 
6
6
  attr_accessor :body
7
7
 
8
- # TODO: Modify once on 1.0.0
9
- def initialize(_protocol, _url = nil)
8
+ def initialize(_config)
10
9
  end
11
10
 
12
11
  def get(_url)
@@ -0,0 +1 @@
1
+ {"status":{"message":"invalid lat/lng", "value":12}}
@@ -0,0 +1 @@
1
+ {"status":{"message":"error parsing parameter","value":14}}
@@ -1,7 +1,9 @@
1
1
  require 'timezone/lookup/basic'
2
2
  require 'minitest/autorun'
3
3
 
4
- class BasicLookupTest < ::Minitest::Unit::TestCase
4
+ class BasicLookupTest < ::Minitest::Test
5
+ parallelize_me!
6
+
5
7
  def config
6
8
  @config ||= Struct.new(:protocol, :url).new('http', 'example.com')
7
9
  end