tzinfo 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of tzinfo might be problematic. Click here for more details.

data/CHANGES CHANGED
@@ -1,3 +1,14 @@
1
+ == Version 0.3.9 (tzdata v2008c) - 27-May-2008
2
+
3
+ * Updated to tzdata version 2008c
4
+ (http://article.gmane.org/gmane.comp.time.tz/2183).
5
+ * Support loading timezone data in the latest trunk versions of Ruby 1.9.
6
+ Rational.new! is now private, so call it using Rational.send :new! instead.
7
+ Thanks to Jeremy Kemper and Pratik Naik for spotting this. Closes #19184.
8
+ * Prevent warnings from being output when running Ruby with the -v or -w
9
+ command line options. Thanks to Paul McMahon for the patch. Closes #19719.
10
+
11
+
1
12
  == Version 0.3.8 (tzdata v2008b) - 24-Mar-2008
2
13
 
3
14
  * Updated to tzdata version 2008b
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ require 'rake/rdoctask'
16
16
  require 'rake/gempackagetask'
17
17
  require 'fileutils'
18
18
 
19
- PKG_VERSION = "0.3.8"
19
+ PKG_VERSION = "0.3.9"
20
20
  PKG_FILES = FileList[
21
21
  'CHANGES',
22
22
  'LICENSE',
@@ -29,6 +29,7 @@ module TZInfo
29
29
  def self.append_features(base)
30
30
  super
31
31
  base.extend(ClassMethods)
32
+ base.instance_eval { @countries = {} }
32
33
  end
33
34
 
34
35
  module ClassMethods #:nodoc:
@@ -36,7 +37,6 @@ module TZInfo
36
37
  # block will be evaluated to obtain all the timezones for the country.
37
38
  # Calls Country.country_defined with the definition of each country.
38
39
  def country(code, name, &block)
39
- @countries = {} unless @countries
40
40
  @countries[code] = CountryInfo.new(code, name, &block)
41
41
  end
42
42
 
@@ -64,12 +64,12 @@ module TZInfo
64
64
 
65
65
  # The latitude of this timezone in degrees as a Rational.
66
66
  def latitude
67
- @latitude ||= Rational.new!(@latitude_numerator, @latitude_denominator)
67
+ @latitude ||= Rational.send(:new!, @latitude_numerator, @latitude_denominator)
68
68
  end
69
69
 
70
70
  # The longitude of this timezone in degrees as a Rational.
71
71
  def longitude
72
- @longitude ||= Rational.new!(@longitude_numerator, @longitude_denominator)
72
+ @longitude ||= Rational.send(:new!, @longitude_numerator, @longitude_denominator)
73
73
  end
74
74
 
75
75
  # Returns true if and only if the given CountryTimezone is equal to the
@@ -40,6 +40,8 @@ module TZInfo
40
40
  super(identifier)
41
41
  @offsets = {}
42
42
  @transitions = []
43
+ @previous_offset = nil
44
+ @transitions_index = nil
43
45
  end
44
46
 
45
47
  # Defines a offset. The id uniquely identifies this offset within the
@@ -31,6 +31,8 @@ module TZInfo
31
31
  tz.transition 1978, 8, :o1, 271033200
32
32
  tz.transition 1984, 3, :o3, 448243200
33
33
  tz.transition 1985, 12, :o1, 504918000
34
+ tz.transition 2008, 6, :o2, 1212278400
35
+ tz.transition 2008, 9, :o1, 1222556400
34
36
  end
35
37
  end
36
38
  end
@@ -12,6 +12,7 @@ module TZInfo
12
12
  tz.offset :o2, 28800, 0, :ULAT
13
13
  tz.offset :o3, 32400, 3600, :CHOST
14
14
  tz.offset :o4, 32400, 0, :CHOT
15
+ tz.offset :o5, 28800, 0, :CHOT
15
16
 
16
17
  tz.transition 1905, 7, :o1, 1740281891, 720
17
18
  tz.transition 1977, 12, :o2, 252435600
@@ -59,6 +60,7 @@ module TZInfo
59
60
  tz.transition 2005, 9, :o4, 1127491200
60
61
  tz.transition 2006, 3, :o3, 1143219600
61
62
  tz.transition 2006, 9, :o4, 1159545600
63
+ tz.transition 2008, 3, :o5, 1206889200
62
64
  end
63
65
  end
64
66
  end
@@ -21,6 +21,8 @@ module TZInfo
21
21
  tz.transition 1971, 3, :o4, 38775600
22
22
  tz.transition 2002, 4, :o5, 1018119660
23
23
  tz.transition 2002, 10, :o4, 1033840860
24
+ tz.transition 2008, 5, :o5, 1212260400
25
+ tz.transition 2008, 8, :o4, 1220205600
24
26
  end
25
27
  end
26
28
  end
@@ -27,63 +27,63 @@ module TZInfo
27
27
  # -14 and +14 hours to avoid having to call gcd at runtime.
28
28
  module OffsetRationals #:nodoc:
29
29
  @@rational_cache = {
30
- -50400 => Rational.new!(-7,12),
31
- -48600 => Rational.new!(-9,16),
32
- -46800 => Rational.new!(-13,24),
33
- -45000 => Rational.new!(-25,48),
34
- -43200 => Rational.new!(-1,2),
35
- -41400 => Rational.new!(-23,48),
36
- -39600 => Rational.new!(-11,24),
37
- -37800 => Rational.new!(-7,16),
38
- -36000 => Rational.new!(-5,12),
39
- -34200 => Rational.new!(-19,48),
40
- -32400 => Rational.new!(-3,8),
41
- -30600 => Rational.new!(-17,48),
42
- -28800 => Rational.new!(-1,3),
43
- -27000 => Rational.new!(-5,16),
44
- -25200 => Rational.new!(-7,24),
45
- -23400 => Rational.new!(-13,48),
46
- -21600 => Rational.new!(-1,4),
47
- -19800 => Rational.new!(-11,48),
48
- -18000 => Rational.new!(-5,24),
49
- -16200 => Rational.new!(-3,16),
50
- -14400 => Rational.new!(-1,6),
51
- -12600 => Rational.new!(-7,48),
52
- -10800 => Rational.new!(-1,8),
53
- -9000 => Rational.new!(-5,48),
54
- -7200 => Rational.new!(-1,12),
55
- -5400 => Rational.new!(-1,16),
56
- -3600 => Rational.new!(-1,24),
57
- -1800 => Rational.new!(-1,48),
58
- 0 => Rational.new!(0,1),
59
- 1800 => Rational.new!(1,48),
60
- 3600 => Rational.new!(1,24),
61
- 5400 => Rational.new!(1,16),
62
- 7200 => Rational.new!(1,12),
63
- 9000 => Rational.new!(5,48),
64
- 10800 => Rational.new!(1,8),
65
- 12600 => Rational.new!(7,48),
66
- 14400 => Rational.new!(1,6),
67
- 16200 => Rational.new!(3,16),
68
- 18000 => Rational.new!(5,24),
69
- 19800 => Rational.new!(11,48),
70
- 21600 => Rational.new!(1,4),
71
- 23400 => Rational.new!(13,48),
72
- 25200 => Rational.new!(7,24),
73
- 27000 => Rational.new!(5,16),
74
- 28800 => Rational.new!(1,3),
75
- 30600 => Rational.new!(17,48),
76
- 32400 => Rational.new!(3,8),
77
- 34200 => Rational.new!(19,48),
78
- 36000 => Rational.new!(5,12),
79
- 37800 => Rational.new!(7,16),
80
- 39600 => Rational.new!(11,24),
81
- 41400 => Rational.new!(23,48),
82
- 43200 => Rational.new!(1,2),
83
- 45000 => Rational.new!(25,48),
84
- 46800 => Rational.new!(13,24),
85
- 48600 => Rational.new!(9,16),
86
- 50400 => Rational.new!(7,12)}
30
+ -50400 => Rational.send(:new!, -7,12),
31
+ -48600 => Rational.send(:new!, -9,16),
32
+ -46800 => Rational.send(:new!, -13,24),
33
+ -45000 => Rational.send(:new!, -25,48),
34
+ -43200 => Rational.send(:new!, -1,2),
35
+ -41400 => Rational.send(:new!, -23,48),
36
+ -39600 => Rational.send(:new!, -11,24),
37
+ -37800 => Rational.send(:new!, -7,16),
38
+ -36000 => Rational.send(:new!, -5,12),
39
+ -34200 => Rational.send(:new!, -19,48),
40
+ -32400 => Rational.send(:new!, -3,8),
41
+ -30600 => Rational.send(:new!, -17,48),
42
+ -28800 => Rational.send(:new!, -1,3),
43
+ -27000 => Rational.send(:new!, -5,16),
44
+ -25200 => Rational.send(:new!, -7,24),
45
+ -23400 => Rational.send(:new!, -13,48),
46
+ -21600 => Rational.send(:new!, -1,4),
47
+ -19800 => Rational.send(:new!, -11,48),
48
+ -18000 => Rational.send(:new!, -5,24),
49
+ -16200 => Rational.send(:new!, -3,16),
50
+ -14400 => Rational.send(:new!, -1,6),
51
+ -12600 => Rational.send(:new!, -7,48),
52
+ -10800 => Rational.send(:new!, -1,8),
53
+ -9000 => Rational.send(:new!, -5,48),
54
+ -7200 => Rational.send(:new!, -1,12),
55
+ -5400 => Rational.send(:new!, -1,16),
56
+ -3600 => Rational.send(:new!, -1,24),
57
+ -1800 => Rational.send(:new!, -1,48),
58
+ 0 => Rational.send(:new!, 0,1),
59
+ 1800 => Rational.send(:new!, 1,48),
60
+ 3600 => Rational.send(:new!, 1,24),
61
+ 5400 => Rational.send(:new!, 1,16),
62
+ 7200 => Rational.send(:new!, 1,12),
63
+ 9000 => Rational.send(:new!, 5,48),
64
+ 10800 => Rational.send(:new!, 1,8),
65
+ 12600 => Rational.send(:new!, 7,48),
66
+ 14400 => Rational.send(:new!, 1,6),
67
+ 16200 => Rational.send(:new!, 3,16),
68
+ 18000 => Rational.send(:new!, 5,24),
69
+ 19800 => Rational.send(:new!, 11,48),
70
+ 21600 => Rational.send(:new!, 1,4),
71
+ 23400 => Rational.send(:new!, 13,48),
72
+ 25200 => Rational.send(:new!, 7,24),
73
+ 27000 => Rational.send(:new!, 5,16),
74
+ 28800 => Rational.send(:new!, 1,3),
75
+ 30600 => Rational.send(:new!, 17,48),
76
+ 32400 => Rational.send(:new!, 3,8),
77
+ 34200 => Rational.send(:new!, 19,48),
78
+ 36000 => Rational.send(:new!, 5,12),
79
+ 37800 => Rational.send(:new!, 7,16),
80
+ 39600 => Rational.send(:new!, 11,24),
81
+ 41400 => Rational.send(:new!, 23,48),
82
+ 43200 => Rational.send(:new!, 1,2),
83
+ 45000 => Rational.send(:new!, 25,48),
84
+ 46800 => Rational.send(:new!, 13,24),
85
+ 48600 => Rational.send(:new!, 9,16),
86
+ 50400 => Rational.send(:new!, 7,12)}
87
87
 
88
88
  # Returns a Rational expressing the fraction of a day that offset in
89
89
  # seconds represents (i.e. equivalent to Rational(offset, 86400)).
@@ -371,8 +371,8 @@ module TZInfo
371
371
  # type as utc. Any timezone information in utc is ignored (it is treated as
372
372
  # a UTC time).
373
373
  def utc_to_local(utc)
374
- TimeOrDateTime.wrap(utc) {|utc|
375
- period_for_utc(utc).to_local(utc)
374
+ TimeOrDateTime.wrap(utc) {|wrapped|
375
+ period_for_utc(wrapped).to_local(wrapped)
376
376
  }
377
377
  end
378
378
 
@@ -410,14 +410,14 @@ module TZInfo
410
410
  # single period to use to convert the time or return nil or an empty array
411
411
  # to cause an AmbiguousTime exception to be raised.
412
412
  def local_to_utc(local, dst = nil)
413
- TimeOrDateTime.wrap(local) {|local|
413
+ TimeOrDateTime.wrap(local) {|wrapped|
414
414
  if block_given?
415
- period = period_for_local(local, dst) {|periods| yield periods }
415
+ period = period_for_local(wrapped, dst) {|periods| yield periods }
416
416
  else
417
- period = period_for_local(local, dst)
417
+ period = period_for_local(wrapped, dst)
418
418
  end
419
419
 
420
- period.to_utc(local)
420
+ period.to_utc(wrapped)
421
421
  }
422
422
  end
423
423
 
@@ -27,21 +27,22 @@ module TZInfo
27
27
  def self.append_features(base)
28
28
  super
29
29
  base.extend(ClassMethods)
30
+ base.instance_eval do
31
+ @timezones = []
32
+ @data_timezones = []
33
+ @linked_timezones = []
34
+ end
30
35
  end
31
36
 
32
37
  module ClassMethods #:nodoc:
33
38
  # Defines a timezone based on data.
34
39
  def timezone(identifier)
35
- @timezones = [] unless @timezones
36
- @data_timezones = [] unless @data_timezones
37
40
  @timezones << identifier
38
41
  @data_timezones << identifier
39
42
  end
40
43
 
41
44
  # Defines a timezone which is a link to another timezone.
42
45
  def linked_timezone(identifier)
43
- @timezones = [] unless @timezones
44
- @linked_timezones = [] unless @linked_timezones
45
46
  @timezones << identifier
46
47
  @linked_timezones << identifier
47
48
  end
@@ -49,14 +50,12 @@ module TZInfo
49
50
  # Returns a frozen array containing the identifiers of all the timezones.
50
51
  # Identifiers appear in the order they were defined in the index.
51
52
  def timezones
52
- @timezones = [] unless @timezones
53
53
  @timezones.freeze
54
54
  end
55
55
 
56
56
  # Returns a frozen array containing the identifiers of all data timezones.
57
57
  # Identifiers appear in the order they were defined in the index.
58
58
  def data_timezones
59
- @data_timezones = [] unless @data_timezones
60
59
  @data_timezones.freeze
61
60
  end
62
61
 
@@ -64,7 +63,6 @@ module TZInfo
64
63
  # timezones. Identifiers appear in the order they were defined in
65
64
  # the index.
66
65
  def linked_timezones
67
- @linked_timezones = [] unless @linked_timezones
68
66
  @linked_timezones.freeze
69
67
  end
70
68
  end
@@ -56,15 +56,15 @@ module TZInfo
56
56
 
57
57
  # Converts a UTC DateTime to local time based on the offset of this period.
58
58
  def to_local(utc)
59
- TimeOrDateTime.wrap(utc) {|utc|
60
- utc + @utc_total_offset
59
+ TimeOrDateTime.wrap(utc) {|wrapped|
60
+ wrapped + @utc_total_offset
61
61
  }
62
62
  end
63
63
 
64
64
  # Converts a local DateTime to UTC based on the offset of this period.
65
65
  def to_utc(local)
66
- TimeOrDateTime.wrap(local) {|local|
67
- local - @utc_total_offset
66
+ TimeOrDateTime.wrap(local) {|wrapped|
67
+ wrapped - @utc_total_offset
68
68
  }
69
69
  end
70
70
 
@@ -48,7 +48,7 @@ module TZInfo
48
48
  # seconds since the epoch. If denominator is specified numerator_or_time
49
49
  # and denominator are used to create a DateTime as follows:
50
50
  #
51
- # DateTime.new!(Rational.new!(numerator_or_time, denominator), 0, Date::ITALY)
51
+ # DateTime.new!(Rational.send(:new!, numerator_or_time, denominator), 0, Date::ITALY)
52
52
  #
53
53
  # For performance reasons, the numerator and denominator must be specified
54
54
  # in their lowest form.
@@ -70,7 +70,7 @@ module TZInfo
70
70
  unless @denominator
71
71
  @at = TimeOrDateTime.new(@numerator_or_time)
72
72
  else
73
- r = Rational.new!(@numerator_or_time, @denominator)
73
+ r = Rational.send(:new!, @numerator_or_time, @denominator)
74
74
 
75
75
  # Ruby 1.8.6 introduced new! and deprecated new0.
76
76
  # Ruby 1.9.0 removed new0.
@@ -1,5 +1,6 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
2
  require 'test/unit'
3
+ require File.join(File.dirname(__FILE__), 'test_utils')
3
4
  require 'tzinfo/country'
4
5
 
5
6
  include TZInfo
@@ -143,8 +144,11 @@ class TCCountry < Test::Unit::TestCase
143
144
 
144
145
  c = Country.get('US')
145
146
  assert_equal('US', Country.get('US').code)
146
-
147
- load 'tzinfo/country.rb'
147
+
148
+ # Suppress redefined method warnings.
149
+ without_warnings do
150
+ load 'tzinfo/country.rb'
151
+ end
148
152
 
149
153
  c = Country.get('US')
150
154
  assert_equal('US', Country.get('US').code)
@@ -1,5 +1,6 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
2
  require 'test/unit'
3
+ require File.join(File.dirname(__FILE__), 'test_utils')
3
4
  require 'tzinfo/linked_timezone'
4
5
  require 'tzinfo/linked_timezone_info'
5
6
 
@@ -48,18 +49,23 @@ class TCLinkedTimezone < Test::Unit::TestCase
48
49
 
49
50
  def setup
50
51
  # Redefine Timezone.get to return a fake timezone.
51
-
52
- def Timezone.get(identifier)
53
- raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier == 'Invalid/Identifier'
54
-
55
- @timezones ||= {}
56
- @timezones[identifier] ||= TestTimezone.new(identifier, identifier == 'Test/No/Local')
52
+ # Use without_warnings to suppress redefined get method warning.
53
+ without_warnings do
54
+ def Timezone.get(identifier)
55
+ raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier == 'Invalid/Identifier'
56
+
57
+ @timezones ||= {}
58
+ @timezones[identifier] ||= TestTimezone.new(identifier, identifier == 'Test/No/Local')
59
+ end
57
60
  end
58
61
  end
59
62
 
60
63
  def teardown
61
64
  # Re-require timezone to reset.
62
- load 'tzinfo/timezone.rb'
65
+ # Suppress redefined method warnings.
66
+ without_warnings do
67
+ load 'tzinfo/timezone.rb'
68
+ end
63
69
  end
64
70
 
65
71
  def test_identifier
@@ -195,8 +195,8 @@ class TCTimezone < Test::Unit::TestCase
195
195
  def test_all_country_zones
196
196
  # Probably should relax this test - just need all the zones, don't care
197
197
  # about order.
198
- expected = Country.all.inject([]) {|expected,country|
199
- expected += country.zones
198
+ expected = Country.all.inject([]) {|result,country|
199
+ result += country.zones
200
200
  }
201
201
  expected.uniq!
202
202
 
@@ -215,8 +215,8 @@ class TCTimezone < Test::Unit::TestCase
215
215
  def test_all_country_zone_identifiers
216
216
  # Probably should relax this test - just need all the zones, don't care
217
217
  # about order.
218
- expected = Country.all.inject([]) {|expected,country|
219
- expected += country.zone_identifiers
218
+ expected = Country.all.inject([]) {|result,country|
219
+ result += country.zone_identifiers
220
220
  }
221
221
  expected.uniq!
222
222
 
@@ -0,0 +1,12 @@
1
+ module Kernel
2
+ # Suppresses any warnings raised in a specified block.
3
+ def without_warnings
4
+ old_verbose = $VERBOSE
5
+ begin
6
+ $VERBOSE = nil
7
+ yield
8
+ ensure
9
+ $-v = old_verbose
10
+ end
11
+ end
12
+ end
@@ -3,4 +3,4 @@
3
3
  ENV['TZ'] = 'America/Los_Angeles'
4
4
 
5
5
  require 'test/unit'
6
- Dir['tc_*.rb'].each {|t| require t}
6
+ Dir[File.join(File.dirname(__FILE__), 'tc_*.rb')].each {|t| require t}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Ross
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-24 00:00:00 +00:00
12
+ date: 2008-05-27 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -659,6 +659,7 @@ files:
659
659
  - test/tc_timezone_transition_info.rb
660
660
  - test/tc_timezone_utc.rb
661
661
  - test/tc_time_or_datetime.rb
662
+ - test/test_utils.rb
662
663
  - test/ts_all.rb
663
664
  has_rdoc: true
664
665
  homepage: http://tzinfo.rubyforge.org/
@@ -685,7 +686,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
685
686
  requirements: []
686
687
 
687
688
  rubyforge_project: tzinfo
688
- rubygems_version: 1.0.1
689
+ rubygems_version: 1.1.1
689
690
  signing_key:
690
691
  specification_version: 2
691
692
  summary: Daylight-savings aware timezone library