timezone 1.1.1 → 1.2.0

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
  SHA1:
3
- metadata.gz: 6a86053f82b0d4454425aeab0810919007923ee4
4
- data.tar.gz: b20264b2d51d7be0d65f05b534e1a835c74951e0
3
+ metadata.gz: 0d9109a87342399c39d7e3a860024d18248e8d11
4
+ data.tar.gz: 730bd61717c5a2de743a34e0cfc7c358f44be7d6
5
5
  SHA512:
6
- metadata.gz: 1653863e3d830cc2a9ea9a8d7220c97ddded649c893de1ce1f9b9f65b77d25ab82cfe139b4511e73498fb18e643c060cdb4888a463cc0204ff00ade64b9c039a
7
- data.tar.gz: aca52242ce0b87377d03a733f6a25b8b0b645b641d2a27cf7c2ce7d3bfbfae19ea1b12b0dd2468bb9ec653adbb4449c6f6d8e225626b28774fcdbc9de87639f8
6
+ metadata.gz: 27cebff1881253bb79164c1259233891bd3589e54c771799c4d56affd25b383b7f2b1fa0acd4302f5ae4beb01aebfc6db37542ffdf250c40806a3ed8c9feb274
7
+ data.tar.gz: 3186874343a8b9294b16848c3e7d1c80adc12d6bb14d4a6f5b2f8704b7a0750a377511473ba62a1048b7abbe9d5329b3ca23ac86964791a65ca918f1cb7f8937
data/CHANGES.markdown CHANGED
@@ -1,5 +1,10 @@
1
1
  # master (unreleased)
2
2
 
3
+ # 1.2.0
4
+
5
+ * Added `::Timezone::Zone#abbr` method. (panthomakos)
6
+ * Handle GeoNames error code 15 - "no result found". (panthomakos)
7
+
3
8
  # 1.1.1
4
9
 
5
10
  * Updated with `tzdata-2016f-1`. (panthomakos)
data/README.markdown CHANGED
@@ -38,6 +38,9 @@ Simple querying of time, in any timezone, is accomplished by first retrieving a
38
38
  timezone.time_with_offset(Time.utc(2010, 1, 1, 0, 0, 0))
39
39
  => 2009-12-31 16:00:00 -0800
40
40
 
41
+ timezone.abbr(Time.new(2016, 9, 4, 1, 0, 0))
42
+ => "PDT"
43
+
41
44
  NOTE: time is always returned in the UTC timezone when using the `utc_to_local` function, but it accurately reflects the actual time in the specified timezone. The reason for this is that this function also takes into account daylight savings time and historical changes in timezone, which can alter the offset. If you want a time with the appropriate offset at the given time, then use the `time_with_offset` function as shown above.
42
45
 
43
46
  You can use the timezone object to convert local times into the best UTC
@@ -7,6 +7,12 @@ module Timezone
7
7
  module Lookup
8
8
  # @!visibility private
9
9
  class Geonames < ::Timezone::Lookup::Basic
10
+ # Status code used by GeoNames to indicate that the lookup succeeded, but
11
+ # there is no timezone information for the given <lat, lng>. This can
12
+ # happen if the <lat, lng> resolves to a point in the middle of the ocean,
13
+ # for example.
14
+ NO_TIMEZONE_INFORMATION = 15
15
+
10
16
  def initialize(config)
11
17
  if config.username.nil?
12
18
  raise(::Timezone::Error::InvalidConfig, 'missing username'.freeze)
@@ -30,6 +36,8 @@ module Timezone
30
36
 
31
37
  return unless data['status']
32
38
 
39
+ return if NO_TIMEZONE_INFORMATION == data['status']['value']
40
+
33
41
  raise(Timezone::Error::GeoNames, data['status']['message'])
34
42
  rescue => e
35
43
  raise(Timezone::Error::GeoNames, e.message)
@@ -1,3 +1,3 @@
1
1
  module Timezone
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
data/lib/timezone/zone.rb CHANGED
@@ -123,6 +123,16 @@ module Timezone
123
123
  Time.new(utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec, offset)
124
124
  end
125
125
 
126
+ # The timezone abbreviation, at the given time.
127
+ #
128
+ # @param time [#to_time] the source time
129
+ # @return [String] the timezone abbreviation, at the given time
130
+ def abbr(time)
131
+ time = sanitize(time)
132
+
133
+ rule_for_utc(time)[NAME_BIT]
134
+ end
135
+
126
136
  # If, at the given time, the timezone was observing Daylight Savings.
127
137
  #
128
138
  # @param time [#to_time] the source time
@@ -0,0 +1 @@
1
+ {"status":{"message":"no timezone information found for lat/lng", "value":15}}
@@ -100,6 +100,13 @@ class TestGeonames < ::Minitest::Test
100
100
  assert_exception(mine, 'invalid lat/lng')
101
101
  end
102
102
 
103
+ def test_no_result_found
104
+ mine = lookup
105
+ mine.client.body = File.open(mock_path + '/no_result_found.json').read
106
+
107
+ assert_nil(mine.lookup(10, 10))
108
+ end
109
+
103
110
  def test_invalid_parameter
104
111
  mine = lookup
105
112
  mine.client.body = File.open(mock_path + '/invalid_parameter.json').read
@@ -30,6 +30,11 @@ class TestZone < ::Minitest::Test
30
30
  assert_equal 'Europe/Paris', paris.name
31
31
  end
32
32
 
33
+ def test_abbr
34
+ assert_equal 'PDT', la.abbr(Time.new(2011, 6, 05))
35
+ assert_equal 'PST', la.abbr(Time.new(2011, 11, 20))
36
+ end
37
+
33
38
  def test_valid?
34
39
  assert la.valid?
35
40
  assert paris.valid?
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.1.1
4
+ version: 1.2.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-07-16 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -702,6 +702,7 @@ files:
702
702
  - test/mocks/lat_lon_coords_atlantic.txt
703
703
  - test/mocks/lat_lon_coords_norfolk.txt
704
704
  - test/mocks/lat_lon_coords_wrong_offset.txt
705
+ - test/mocks/no_result_found.json
705
706
  - test/test_timezone.rb
706
707
  - test/timezone/lookup/test_basic.rb
707
708
  - test/timezone/lookup/test_geonames.rb
@@ -738,7 +739,7 @@ rubyforge_project: timezone
738
739
  rubygems_version: 2.4.5.1
739
740
  signing_key:
740
741
  specification_version: 4
741
- summary: timezone-1.1.1
742
+ summary: timezone-1.2.0
742
743
  test_files:
743
744
  - test/data/Helsinki_rules_without_timestamps.json
744
745
  - test/data/asia
@@ -753,6 +754,7 @@ test_files:
753
754
  - test/mocks/lat_lon_coords_atlantic.txt
754
755
  - test/mocks/lat_lon_coords_norfolk.txt
755
756
  - test/mocks/lat_lon_coords_wrong_offset.txt
757
+ - test/mocks/no_result_found.json
756
758
  - test/test_timezone.rb
757
759
  - test/timezone/lookup/test_basic.rb
758
760
  - test/timezone/lookup/test_geonames.rb