tzinfo 1.0.1 → 1.1.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.yardopts +6 -0
- data/{CHANGES → CHANGES.md} +121 -50
- data/{README → README.md} +48 -34
- data/Rakefile +45 -22
- data/lib/tzinfo.rb +7 -2
- data/lib/tzinfo/country.rb +23 -1
- data/lib/tzinfo/country_index_definition.rb +6 -1
- data/lib/tzinfo/country_timezone.rb +9 -1
- data/lib/tzinfo/data_source.rb +26 -5
- data/lib/tzinfo/data_timezone.rb +30 -2
- data/lib/tzinfo/data_timezone_info.rb +26 -0
- data/lib/tzinfo/info_timezone.rb +3 -1
- data/lib/tzinfo/linked_timezone.rb +30 -1
- data/lib/tzinfo/offset_rationals.rb +5 -3
- data/lib/tzinfo/ruby_core_support.rb +2 -0
- data/lib/tzinfo/ruby_country_info.rb +14 -0
- data/lib/tzinfo/ruby_data_source.rb +5 -0
- data/lib/tzinfo/time_or_datetime.rb +16 -1
- data/lib/tzinfo/timezone.rb +107 -5
- data/lib/tzinfo/timezone_definition.rb +5 -1
- data/lib/tzinfo/timezone_index_definition.rb +7 -1
- data/lib/tzinfo/{timezone_offset_info.rb → timezone_offset.rb} +12 -10
- data/lib/tzinfo/timezone_period.rb +19 -15
- data/lib/tzinfo/timezone_proxy.rb +5 -1
- data/lib/tzinfo/timezone_transition.rb +136 -0
- data/lib/tzinfo/{timezone_transition_info.rb → timezone_transition_definition.rb} +21 -57
- data/lib/tzinfo/transition_data_timezone_info.rb +81 -8
- data/lib/tzinfo/zoneinfo_country_info.rb +7 -0
- data/lib/tzinfo/zoneinfo_data_source.rb +104 -57
- data/lib/tzinfo/zoneinfo_timezone_info.rb +18 -10
- data/test/tc_country.rb +39 -1
- data/test/tc_data_timezone.rb +28 -5
- data/test/tc_linked_timezone.rb +24 -3
- data/test/tc_ruby_data_source.rb +22 -2
- data/test/tc_time_or_datetime.rb +3 -3
- data/test/tc_timezone.rb +364 -117
- data/test/tc_timezone_london.rb +25 -0
- data/test/tc_timezone_melbourne.rb +24 -0
- data/test/tc_timezone_new_york.rb +24 -0
- data/test/{tc_timezone_offset_info.rb → tc_timezone_offset.rb} +27 -27
- data/test/tc_timezone_period.rb +113 -90
- data/test/tc_timezone_transition.rb +374 -0
- data/test/tc_timezone_transition_definition.rb +306 -0
- data/test/tc_transition_data_timezone_info.rb +143 -43
- data/test/tc_zoneinfo_data_source.rb +69 -5
- data/test/tc_zoneinfo_timezone_info.rb +63 -20
- data/test/test_utils.rb +27 -7
- data/tzinfo.gemspec +21 -0
- metadata +61 -38
- metadata.gz.sig +3 -0
- data/test/tc_timezone_transition_info.rb +0 -471
- data/test/zoneinfo/UTC +0 -0
- data/test/zoneinfo/localtime +0 -0
data/{README → README.md}
RENAMED
@@ -1,18 +1,20 @@
|
|
1
|
-
|
1
|
+
TZInfo - Ruby Timezone Library
|
2
|
+
==============================
|
2
3
|
|
3
|
-
TZInfo
|
4
|
+
[TZInfo](http://tzinfo.github.io) provides daylight savings aware
|
4
5
|
transformations between times in different timezones.
|
5
6
|
|
6
7
|
|
7
|
-
|
8
|
+
Data Sources
|
9
|
+
------------
|
8
10
|
|
9
11
|
TZInfo requires a source of timezone data. There are two built-in options:
|
10
12
|
|
11
13
|
1. The TZInfo::Data library (the tzinfo-data gem). TZInfo::Data contains a set
|
12
|
-
of Ruby modules that are generated from the
|
14
|
+
of Ruby modules that are generated from the [IANA Time Zone Database](http://www.iana.org/time-zones).
|
13
15
|
2. A zoneinfo directory. Most Unix-like systems include a zoneinfo directory
|
14
16
|
containing timezone definitions. These are also generated from the
|
15
|
-
|
17
|
+
[IANA Time Zone Database](http://www.iana.org/time-zones).
|
16
18
|
|
17
19
|
By default, TZInfo::Data will be used. If TZInfo::Data is not available (i.e.
|
18
20
|
if require 'tzinfo/data' fails), then TZInfo will search for a zoneinfo
|
@@ -29,33 +31,29 @@ Custom data sources can also be used. See TZInfo::DataSource.set for
|
|
29
31
|
further details.
|
30
32
|
|
31
33
|
|
32
|
-
|
34
|
+
Installation
|
35
|
+
------------
|
33
36
|
|
34
37
|
The TZInfo gem can be installed by running:
|
35
38
|
|
36
|
-
|
39
|
+
gem install tzinfo
|
37
40
|
|
38
41
|
To use the Ruby modules as the data source, TZInfo::Data will also need to be
|
39
42
|
installed:
|
40
43
|
|
41
|
-
|
44
|
+
gem install tzinfo-data
|
42
45
|
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
Tar, Zip and RubyGem packages of TZInfo and TZInfo::Data can be downloaded from
|
47
|
-
http://rubyforge.org/frs/?group_id=894
|
48
|
-
|
49
|
-
|
50
|
-
== Example usage
|
47
|
+
Example Usage
|
48
|
+
-------------
|
51
49
|
|
52
50
|
The following code will obtain the America/New_York timezone (as an instance
|
53
51
|
of TZInfo::Timezone) and covert a time in UTC to local New York time:
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
require 'tzinfo'
|
54
|
+
|
55
|
+
tz = TZInfo::Timezone.get('America/New_York')
|
56
|
+
local = tz.utc_to_local(Time.utc(2005,8,29,15,35,0))
|
59
57
|
|
60
58
|
Note that the local Time returned will have a UTC timezone (local.zone will
|
61
59
|
return "UTC"). This is because the Ruby Time class only supports two timezones:
|
@@ -64,28 +62,28 @@ UTC and the current system local timezone.
|
|
64
62
|
To convert from a local time to UTC, the local_to_utc method can be used as
|
65
63
|
follows:
|
66
64
|
|
67
|
-
|
65
|
+
utc = tz.local_to_utc(local)
|
68
66
|
|
69
67
|
Note that the timezone information of the local Time object is ignored (TZInfo
|
70
68
|
will just read the date and time and treat them as if there were in the 'tz'
|
71
69
|
timezone). The following two lines will return the same result regardless of
|
72
70
|
the system's local timezone:
|
73
71
|
|
74
|
-
|
75
|
-
|
72
|
+
tz.local_to_utc(Time.local(2006,6,26,1,0,0))
|
73
|
+
tz.local_to_utc(Time.utc(2006,6,26,1,0,0))
|
76
74
|
|
77
75
|
To obtain information about the rules in force at a particular UTC or local
|
78
76
|
time, the TZInfo::Timezone.period_for_utc and TZInfo::Timezone.period_for_local
|
79
77
|
methods can be used. Both of these methods return TZInfo::TimezonePeriod
|
80
78
|
objects. The following gets the identifier for the period (in this case EDT).
|
81
79
|
|
82
|
-
|
83
|
-
|
80
|
+
period = tz.period_for_utc(Time.utc(2005,8,29,15,35,0))
|
81
|
+
id = period.zone_identifier
|
84
82
|
|
85
83
|
The current local time in a Timezone can be obtained with the
|
86
84
|
TZInfo::Timezone#now method:
|
87
85
|
|
88
|
-
|
86
|
+
now = tz.now
|
89
87
|
|
90
88
|
All methods in TZInfo that operate on a time can be used with either Time or
|
91
89
|
DateTime instances or with Integer timestamps (i.e. as returned by Time#to_i).
|
@@ -100,8 +98,8 @@ code). The following code retrieves the TZInfo::Country instance representing
|
|
100
98
|
the USA (country code 'US') and then gets all the Timezone identifiers used in
|
101
99
|
the USA.
|
102
100
|
|
103
|
-
|
104
|
-
|
101
|
+
us = TZInfo::Country.get('US')
|
102
|
+
timezones = us.zone_identifiers
|
105
103
|
|
106
104
|
The TZInfo::Country#zone_info method provides an additional description and
|
107
105
|
geographic location for each Timezone in a Country.
|
@@ -114,19 +112,35 @@ For further detail, please refer to the API documentation for the
|
|
114
112
|
TZInfo::Timezone and TZInfo::Country classes.
|
115
113
|
|
116
114
|
|
117
|
-
|
115
|
+
Thread-Safety
|
116
|
+
-------------
|
117
|
+
|
118
|
+
The TZInfo::Country and TZInfo::Timezone classes are thread-safe. It is safe to
|
119
|
+
use class and instance methods of TZInfo::Country and TZInfo::Timezone in
|
120
|
+
concurrently executing threads. Instances of both classes can be shared across
|
121
|
+
thread boundaries.
|
118
122
|
|
119
|
-
API documentation can be found at
|
120
123
|
|
121
|
-
|
124
|
+
Documentation
|
125
|
+
-------------
|
122
126
|
|
127
|
+
API documentation for TZInfo is available on [RubyDoc.info](http://rubydoc.info/gems/tzinfo/frames).
|
123
128
|
|
124
|
-
|
129
|
+
|
130
|
+
License
|
131
|
+
-------
|
125
132
|
|
126
133
|
TZInfo is released under the MIT license, see LICENSE for details.
|
127
134
|
|
128
135
|
|
129
|
-
|
136
|
+
Source Code
|
137
|
+
-----------
|
138
|
+
|
139
|
+
Source code for TZInfo is available on [GitHub](https://github.com/tzinfo/tzinfo).
|
140
|
+
|
141
|
+
|
142
|
+
Issue Tracker
|
143
|
+
-------------
|
130
144
|
|
131
|
-
Please post
|
132
|
-
|
145
|
+
Please post any bugs, issues, feature requests or questions to the
|
146
|
+
[GitHub issue tracker](https://github.com/tzinfo/tzinfo/issues).
|
data/Rakefile
CHANGED
@@ -1,15 +1,40 @@
|
|
1
|
-
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2005-2013 Philip Ross
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
2
13
|
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#++
|
6
22
|
|
7
|
-
require 'rake'
|
8
|
-
require 'rake/testtask'
|
9
|
-
require 'rdoc/task'
|
10
23
|
require 'rubygems'
|
11
24
|
require 'rubygems/package_task'
|
12
25
|
require 'fileutils'
|
26
|
+
require 'rake/testtask'
|
27
|
+
|
28
|
+
# Ignore errors loading rdoc/task (the rdoc tasks will be excluded if
|
29
|
+
# rdoc is unavailable).
|
30
|
+
begin
|
31
|
+
require 'rdoc/task'
|
32
|
+
rescue LoadError, RuntimeError
|
33
|
+
end
|
34
|
+
|
35
|
+
BASE_DIR = File.expand_path(File.dirname(__FILE__))
|
36
|
+
|
37
|
+
task :default => [:test]
|
13
38
|
|
14
39
|
spec = eval(File.read('tzinfo.gemspec'))
|
15
40
|
|
@@ -34,17 +59,17 @@ package_task = TZInfoPackageTask.new(spec) do |pkg|
|
|
34
59
|
pkg.tar_command = '__tar_with_owner__'
|
35
60
|
end
|
36
61
|
|
37
|
-
RDoc::Task
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
62
|
+
# Skip the rdoc task if RDoc::Task is unavailable
|
63
|
+
if defined?(RDoc) && defined?(RDoc::Task)
|
64
|
+
RDoc::Task.new do |rdoc|
|
65
|
+
rdoc.rdoc_dir = 'doc'
|
66
|
+
rdoc.options.concat spec.rdoc_options
|
67
|
+
rdoc.rdoc_files.include(spec.extra_rdoc_files)
|
68
|
+
rdoc.rdoc_files.include('lib')
|
69
|
+
end
|
44
70
|
end
|
45
71
|
|
46
72
|
Rake::Task[package_task.package_dir_path].enhance do
|
47
|
-
File.chmod(0755, package_task.package_dir_path)
|
48
73
|
recurse_chmod(package_task.package_dir_path)
|
49
74
|
end
|
50
75
|
|
@@ -67,21 +92,19 @@ def recurse_chmod(dir)
|
|
67
92
|
end
|
68
93
|
end
|
69
94
|
|
95
|
+
desc 'Run tests using RubyDataSource, then ZoneinfoDataSource'
|
70
96
|
task :test => [:test_ruby, :test_zoneinfo] do
|
71
97
|
end
|
72
98
|
|
73
99
|
def setup_tests(test_task, type)
|
74
|
-
|
75
|
-
|
76
|
-
ENV['TZ'] = 'America/Los_Angeles'
|
77
|
-
|
78
|
-
test_task.pattern = File.join(File.expand_path(File.dirname(__FILE__)), 'test', "ts_all_#{type}.rb")
|
100
|
+
test_task.libs = [File.join(BASE_DIR, 'lib')]
|
101
|
+
test_task.pattern = File.join(BASE_DIR, 'test', "ts_all_#{type}.rb")
|
79
102
|
end
|
80
103
|
|
81
|
-
Rake::TestTask.new(
|
104
|
+
Rake::TestTask.new(:test_ruby) do |t|
|
82
105
|
setup_tests(t, :ruby)
|
83
106
|
end
|
84
107
|
|
85
|
-
Rake::TestTask.new(
|
108
|
+
Rake::TestTask.new(:test_zoneinfo) do |t|
|
86
109
|
setup_tests(t, :zoneinfo)
|
87
110
|
end
|
data/lib/tzinfo.rb
CHANGED
@@ -20,14 +20,19 @@
|
|
20
20
|
# THE SOFTWARE.
|
21
21
|
#++
|
22
22
|
|
23
|
+
# Top level module for TZInfo.
|
24
|
+
module TZInfo
|
25
|
+
end
|
26
|
+
|
23
27
|
require 'tzinfo/ruby_core_support'
|
24
28
|
require 'tzinfo/offset_rationals'
|
25
29
|
require 'tzinfo/time_or_datetime'
|
26
30
|
|
27
31
|
require 'tzinfo/timezone_definition'
|
28
32
|
|
29
|
-
require 'tzinfo/
|
30
|
-
require 'tzinfo/
|
33
|
+
require 'tzinfo/timezone_offset'
|
34
|
+
require 'tzinfo/timezone_transition'
|
35
|
+
require 'tzinfo/timezone_transition_definition'
|
31
36
|
|
32
37
|
require 'tzinfo/timezone_index_definition'
|
33
38
|
|
data/lib/tzinfo/country.rb
CHANGED
@@ -20,6 +20,8 @@
|
|
20
20
|
# THE SOFTWARE.
|
21
21
|
#++
|
22
22
|
|
23
|
+
require 'thread_safe'
|
24
|
+
|
23
25
|
module TZInfo
|
24
26
|
# Raised by Country#get if the code given is not valid.
|
25
27
|
class InvalidCountryCode < StandardError
|
@@ -33,6 +35,10 @@ module TZInfo
|
|
33
35
|
# us.zones
|
34
36
|
# us.zone_info
|
35
37
|
#
|
38
|
+
# The Country class is thread-safe. It is safe to use class and instance
|
39
|
+
# methods of Country in concurrently executing threads. Instances of Country
|
40
|
+
# can be shared across thread boundaries.
|
41
|
+
#
|
36
42
|
# Country information available through TZInfo is intended as an aid for
|
37
43
|
# users, to help them select time zone data appropriate for their practical
|
38
44
|
# needs. It is not intended to take or endorse any position on legal or
|
@@ -41,9 +47,13 @@ module TZInfo
|
|
41
47
|
include Comparable
|
42
48
|
|
43
49
|
# Defined countries.
|
44
|
-
|
50
|
+
#
|
51
|
+
# @!visibility private
|
52
|
+
@@countries = nil
|
45
53
|
|
46
54
|
# Whether the countries index has been loaded yet.
|
55
|
+
#
|
56
|
+
# @!visibility private
|
47
57
|
@@index_loaded = false
|
48
58
|
|
49
59
|
# Gets a Country by its ISO 3166-1 alpha-2 code. Raises an
|
@@ -52,6 +62,13 @@ module TZInfo
|
|
52
62
|
instance = @@countries[identifier]
|
53
63
|
|
54
64
|
unless instance
|
65
|
+
# Thread-safety: It is possible that multiple equivalent Country
|
66
|
+
# instances could be created here in concurrently executing threads.
|
67
|
+
# The consequences of this are that the data may be loaded more than
|
68
|
+
# once (depending on the data source) and memoized calculations could
|
69
|
+
# be discarded. The performance benefit of ensuring that only a single
|
70
|
+
# instance is created is unlikely to be worth the overhead of only
|
71
|
+
# allowing one Country to be loaded at a time.
|
55
72
|
info = data_source.load_country_info(identifier)
|
56
73
|
instance = Country.new(info)
|
57
74
|
@@countries[identifier] = instance
|
@@ -169,6 +186,11 @@ module TZInfo
|
|
169
186
|
@info = info
|
170
187
|
end
|
171
188
|
|
189
|
+
def self.init_countries
|
190
|
+
@@countries = ThreadSafe::Cache.new
|
191
|
+
end
|
192
|
+
init_countries
|
193
|
+
|
172
194
|
# Returns the current DataSource
|
173
195
|
def self.data_source
|
174
196
|
DataSource.get
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2006-
|
2
|
+
# Copyright (c) 2006-2013 Philip Ross
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -23,6 +23,8 @@
|
|
23
23
|
module TZInfo
|
24
24
|
# The country index file includes CountryIndexDefinition which provides
|
25
25
|
# a country method used to define each country in the index.
|
26
|
+
#
|
27
|
+
# @private
|
26
28
|
module CountryIndexDefinition #:nodoc:
|
27
29
|
def self.append_features(base)
|
28
30
|
super
|
@@ -30,6 +32,9 @@ module TZInfo
|
|
30
32
|
base.instance_eval { @countries = {} }
|
31
33
|
end
|
32
34
|
|
35
|
+
# Class methods for inclusion.
|
36
|
+
#
|
37
|
+
# @private
|
33
38
|
module ClassMethods #:nodoc:
|
34
39
|
# Defines a country with an ISO 3166 country code, name and block. The
|
35
40
|
# block will be evaluated to obtain all the timezones for the country.
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2006-
|
2
|
+
# Copyright (c) 2006-2013 Philip Ross
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -62,11 +62,19 @@ module TZInfo
|
|
62
62
|
|
63
63
|
# The latitude of this timezone in degrees as a Rational.
|
64
64
|
def latitude
|
65
|
+
# Thread-safey: It is possible that the value of @latitude may be
|
66
|
+
# calculated multiple times in concurrently executing threads. It is not
|
67
|
+
# worth the overhead of locking to ensure that @latitude is only
|
68
|
+
# calculated once.
|
65
69
|
@latitude ||= RubyCoreSupport.rational_new!(@latitude_numerator, @latitude_denominator)
|
66
70
|
end
|
67
71
|
|
68
72
|
# The longitude of this timezone in degrees as a Rational.
|
69
73
|
def longitude
|
74
|
+
# Thread-safey: It is possible that the value of @longitude may be
|
75
|
+
# calculated multiple times in concurrently executing threads. It is not
|
76
|
+
# worth the overhead of locking to ensure that @longitude is only
|
77
|
+
# calculated once.
|
70
78
|
@longitude ||= RubyCoreSupport.rational_new!(@longitude_numerator, @longitude_denominator)
|
71
79
|
end
|
72
80
|
|
data/lib/tzinfo/data_source.rb
CHANGED
@@ -20,6 +20,8 @@
|
|
20
20
|
# THE SOFTWARE.
|
21
21
|
#++
|
22
22
|
|
23
|
+
require 'thread'
|
24
|
+
|
23
25
|
module TZInfo
|
24
26
|
# InvalidDataSource is raised if the DataSource is used doesn't implement one
|
25
27
|
# of the required methods.
|
@@ -38,10 +40,29 @@ module TZInfo
|
|
38
40
|
class DataSource
|
39
41
|
# The currently selected data source.
|
40
42
|
@@instance = nil
|
43
|
+
|
44
|
+
# Mutex used to ensure the default data source is only created once.
|
45
|
+
@@default_mutex = Mutex.new
|
41
46
|
|
42
47
|
# Returns the currently selected DataSource instance.
|
43
48
|
def self.get
|
44
|
-
set
|
49
|
+
# If a DataSource hasn't been manually set when the first request is
|
50
|
+
# made to obtain a DataSource, then a Default data source is created.
|
51
|
+
|
52
|
+
# This is done at the first request rather than when TZInfo is loaded to
|
53
|
+
# avoid unnecessary (or in some cases potentially harmful) attempts to
|
54
|
+
# find a suitable DataSource.
|
55
|
+
|
56
|
+
# A Mutex is used to ensure that only a single default instance is
|
57
|
+
# created (having two different DataSources in use simultaneously could
|
58
|
+
# cause unexpected results).
|
59
|
+
|
60
|
+
unless @@instance
|
61
|
+
@@default_mutex.synchronize do
|
62
|
+
set(create_default_data_source) unless @@instance
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
45
66
|
@@instance
|
46
67
|
end
|
47
68
|
|
@@ -88,10 +109,10 @@ module TZInfo
|
|
88
109
|
# To avoid inconsistent data, \DataSource.set should be called before
|
89
110
|
# accessing any Timezone or Country data.
|
90
111
|
#
|
91
|
-
# If \DataSource.set is not called, TZInfo will use TZInfo::Data
|
92
|
-
# data source. If TZInfo::Data is not available (i.e. if
|
93
|
-
#
|
94
|
-
#
|
112
|
+
# If \DataSource.set is not called, TZInfo will by default use TZInfo::Data
|
113
|
+
# as the data source. If TZInfo::Data is not available (i.e. if require
|
114
|
+
# 'tzinfo/data' fails), then TZInfo will search for a zoneinfo directory
|
115
|
+
# instead (using the search path specified by
|
95
116
|
# TZInfo::ZoneinfoDataSource::DEFAULT_SEARCH_PATH).
|
96
117
|
def self.set(data_source_or_type, *args)
|
97
118
|
if data_source_or_type.kind_of?(DataSource)
|
data/lib/tzinfo/data_timezone.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2006-
|
2
|
+
# Copyright (c) 2006-2013 Philip Ross
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -23,6 +23,8 @@
|
|
23
23
|
module TZInfo
|
24
24
|
|
25
25
|
# A Timezone based on a DataTimezoneInfo.
|
26
|
+
#
|
27
|
+
# @private
|
26
28
|
class DataTimezone < InfoTimezone #:nodoc:
|
27
29
|
|
28
30
|
# Returns the TimezonePeriod for the given UTC time. utc can either be
|
@@ -40,6 +42,32 @@ module TZInfo
|
|
40
42
|
# Raises PeriodNotFound if no periods are found for the given time.
|
41
43
|
def periods_for_local(local)
|
42
44
|
info.periods_for_local(local)
|
43
|
-
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns an Array of TimezoneTransition instances representing the times
|
48
|
+
# where the UTC offset of the timezone changes.
|
49
|
+
#
|
50
|
+
# Transitions are returned up to a given date and time up to a given date
|
51
|
+
# and time, specified in UTC (utc_to).
|
52
|
+
#
|
53
|
+
# A from date and time may also be supplied using the utc_from parameter
|
54
|
+
# (also specified in UTC). If utc_from is not nil, only transitions from
|
55
|
+
# that date and time onwards will be returned.
|
56
|
+
#
|
57
|
+
# Comparisons with utc_to are exclusive. Comparisons with utc_from are
|
58
|
+
# inclusive. If a transition falls precisely on utc_to, it will be excluded.
|
59
|
+
# If a transition falls on utc_from, it will be included.
|
60
|
+
#
|
61
|
+
# Transitions returned are ordered by when they occur, from earliest to
|
62
|
+
# latest.
|
63
|
+
#
|
64
|
+
# utc_to and utc_from can be specified using either DateTime, Time or
|
65
|
+
# integer timestamps (Time.to_i).
|
66
|
+
#
|
67
|
+
# If utc_from is specified and utc_to is not greater than utc_from, then
|
68
|
+
# transitions_up_to raises an ArgumentError exception.
|
69
|
+
def transitions_up_to(utc_to, utc_from = nil)
|
70
|
+
info.transitions_up_to(utc_to, utc_from)
|
71
|
+
end
|
44
72
|
end
|
45
73
|
end
|