tzinfo 1.2.5
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 +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/.yardopts +6 -0
- data/CHANGES.md +786 -0
- data/LICENSE +19 -0
- data/README.md +151 -0
- data/Rakefile +107 -0
- data/lib/tzinfo.rb +40 -0
- data/lib/tzinfo/country.rb +196 -0
- data/lib/tzinfo/country_index_definition.rb +31 -0
- data/lib/tzinfo/country_info.rb +42 -0
- data/lib/tzinfo/country_timezone.rb +135 -0
- data/lib/tzinfo/data_source.rb +190 -0
- data/lib/tzinfo/data_timezone.rb +58 -0
- data/lib/tzinfo/data_timezone_info.rb +55 -0
- data/lib/tzinfo/info_timezone.rb +30 -0
- data/lib/tzinfo/linked_timezone.rb +63 -0
- data/lib/tzinfo/linked_timezone_info.rb +26 -0
- data/lib/tzinfo/offset_rationals.rb +77 -0
- data/lib/tzinfo/ruby_core_support.rb +146 -0
- data/lib/tzinfo/ruby_country_info.rb +74 -0
- data/lib/tzinfo/ruby_data_source.rb +136 -0
- data/lib/tzinfo/time_or_datetime.rb +340 -0
- data/lib/tzinfo/timezone.rb +669 -0
- data/lib/tzinfo/timezone_definition.rb +36 -0
- data/lib/tzinfo/timezone_index_definition.rb +54 -0
- data/lib/tzinfo/timezone_info.rb +30 -0
- data/lib/tzinfo/timezone_offset.rb +101 -0
- data/lib/tzinfo/timezone_period.rb +245 -0
- data/lib/tzinfo/timezone_proxy.rb +105 -0
- data/lib/tzinfo/timezone_transition.rb +130 -0
- data/lib/tzinfo/timezone_transition_definition.rb +104 -0
- data/lib/tzinfo/transition_data_timezone_info.rb +274 -0
- data/lib/tzinfo/zoneinfo_country_info.rb +37 -0
- data/lib/tzinfo/zoneinfo_data_source.rb +488 -0
- data/lib/tzinfo/zoneinfo_timezone_info.rb +296 -0
- data/test/tc_country.rb +234 -0
- data/test/tc_country_index_definition.rb +69 -0
- data/test/tc_country_info.rb +16 -0
- data/test/tc_country_timezone.rb +173 -0
- data/test/tc_data_source.rb +218 -0
- data/test/tc_data_timezone.rb +99 -0
- data/test/tc_data_timezone_info.rb +18 -0
- data/test/tc_info_timezone.rb +34 -0
- data/test/tc_linked_timezone.rb +155 -0
- data/test/tc_linked_timezone_info.rb +23 -0
- data/test/tc_offset_rationals.rb +23 -0
- data/test/tc_ruby_core_support.rb +168 -0
- data/test/tc_ruby_country_info.rb +110 -0
- data/test/tc_ruby_data_source.rb +143 -0
- data/test/tc_time_or_datetime.rb +654 -0
- data/test/tc_timezone.rb +1350 -0
- data/test/tc_timezone_definition.rb +113 -0
- data/test/tc_timezone_index_definition.rb +73 -0
- data/test/tc_timezone_info.rb +11 -0
- data/test/tc_timezone_london.rb +143 -0
- data/test/tc_timezone_melbourne.rb +142 -0
- data/test/tc_timezone_new_york.rb +142 -0
- data/test/tc_timezone_offset.rb +126 -0
- data/test/tc_timezone_period.rb +555 -0
- data/test/tc_timezone_proxy.rb +136 -0
- data/test/tc_timezone_transition.rb +366 -0
- data/test/tc_timezone_transition_definition.rb +295 -0
- data/test/tc_timezone_utc.rb +27 -0
- data/test/tc_transition_data_timezone_info.rb +423 -0
- data/test/tc_zoneinfo_country_info.rb +78 -0
- data/test/tc_zoneinfo_data_source.rb +1195 -0
- data/test/tc_zoneinfo_timezone_info.rb +1232 -0
- data/test/test_utils.rb +163 -0
- data/test/ts_all.rb +7 -0
- data/test/ts_all_ruby.rb +5 -0
- data/test/ts_all_zoneinfo.rb +7 -0
- data/test/tzinfo-data/tzinfo/data.rb +8 -0
- data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +89 -0
- data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +315 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +218 -0
- data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +19 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +21 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +21 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +21 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +261 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +186 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +321 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +265 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +220 -0
- data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +16 -0
- data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +927 -0
- data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +596 -0
- data/test/tzinfo-data/tzinfo/data/version.rb +14 -0
- data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
- data/test/zoneinfo/America/New_York +0 -0
- data/test/zoneinfo/Australia/Melbourne +0 -0
- data/test/zoneinfo/EST +0 -0
- data/test/zoneinfo/Etc/UTC +0 -0
- data/test/zoneinfo/Europe/Amsterdam +0 -0
- data/test/zoneinfo/Europe/Andorra +0 -0
- data/test/zoneinfo/Europe/London +0 -0
- data/test/zoneinfo/Europe/Paris +0 -0
- data/test/zoneinfo/Europe/Prague +0 -0
- data/test/zoneinfo/Factory +0 -0
- data/test/zoneinfo/iso3166.tab +275 -0
- data/test/zoneinfo/leapseconds +61 -0
- data/test/zoneinfo/posix/Europe/London +0 -0
- data/test/zoneinfo/posixrules +0 -0
- data/test/zoneinfo/right/Europe/London +0 -0
- data/test/zoneinfo/zone.tab +439 -0
- data/test/zoneinfo/zone1970.tab +369 -0
- data/tzinfo.gemspec +21 -0
- metadata +193 -0
- metadata.gz.sig +2 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
module TZInfo
|
2
|
+
# The country index file includes CountryIndexDefinition which provides
|
3
|
+
# a country method used to define each country in the index.
|
4
|
+
#
|
5
|
+
# @private
|
6
|
+
module CountryIndexDefinition #:nodoc:
|
7
|
+
def self.append_features(base)
|
8
|
+
super
|
9
|
+
base.extend(ClassMethods)
|
10
|
+
base.instance_eval { @countries = {} }
|
11
|
+
end
|
12
|
+
|
13
|
+
# Class methods for inclusion.
|
14
|
+
#
|
15
|
+
# @private
|
16
|
+
module ClassMethods #:nodoc:
|
17
|
+
# Defines a country with an ISO 3166 country code, name and block. The
|
18
|
+
# block will be evaluated to obtain all the timezones for the country.
|
19
|
+
# Calls Country.country_defined with the definition of each country.
|
20
|
+
def country(code, name, &block)
|
21
|
+
@countries[code] = RubyCountryInfo.new(code, name, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns a frozen hash of all the countries that have been defined in
|
25
|
+
# the index.
|
26
|
+
def countries
|
27
|
+
@countries.freeze
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module TZInfo
|
2
|
+
# Represents a country and references to its timezones as returned by a
|
3
|
+
# DataSource.
|
4
|
+
class CountryInfo
|
5
|
+
# The ISO 3166 country code.
|
6
|
+
attr_reader :code
|
7
|
+
|
8
|
+
# The name of the country.
|
9
|
+
attr_reader :name
|
10
|
+
|
11
|
+
# Constructs a new CountryInfo with an ISO 3166 country code and name
|
12
|
+
def initialize(code, name)
|
13
|
+
@code = code
|
14
|
+
@name = name
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns internal object state as a programmer-readable string.
|
18
|
+
def inspect
|
19
|
+
"#<#{self.class}: #@code>"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns a frozen array of all the zone identifiers for the country.
|
23
|
+
# The identifiers are ordered by importance according to the DataSource.
|
24
|
+
def zone_identifiers
|
25
|
+
raise_not_implemented('zone_identifiers')
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns a frozen array of all the timezones for the for the country as
|
29
|
+
# CountryTimezone instances.
|
30
|
+
#
|
31
|
+
# The timezones are ordered by importance according to the DataSource.
|
32
|
+
def zones
|
33
|
+
raise_not_implemented('zones')
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def raise_not_implemented(method_name)
|
39
|
+
raise NotImplementedError, "Subclasses must override #{method_name}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module TZInfo
|
2
|
+
# A Timezone within a Country. This contains extra information about the
|
3
|
+
# Timezone that is specific to the Country (a Timezone could be used by
|
4
|
+
# multiple countries).
|
5
|
+
class CountryTimezone
|
6
|
+
# The zone identifier.
|
7
|
+
attr_reader :identifier
|
8
|
+
|
9
|
+
# A description of this timezone in relation to the country, e.g.
|
10
|
+
# "Eastern Time". This is usually nil for countries having only a single
|
11
|
+
# Timezone.
|
12
|
+
attr_reader :description
|
13
|
+
|
14
|
+
class << self
|
15
|
+
# Creates a new CountryTimezone with a timezone identifier, latitude,
|
16
|
+
# longitude and description. The latitude and longitude are specified as
|
17
|
+
# rationals - a numerator and denominator. For performance reasons, the
|
18
|
+
# numerators and denominators must be specified in their lowest form.
|
19
|
+
#
|
20
|
+
# For use internally within TZInfo.
|
21
|
+
#
|
22
|
+
# @!visibility private
|
23
|
+
alias :new! :new
|
24
|
+
|
25
|
+
# Creates a new CountryTimezone with a timezone identifier, latitude,
|
26
|
+
# longitude and description. The latitude and longitude must be specified
|
27
|
+
# as instances of Rational.
|
28
|
+
#
|
29
|
+
# CountryTimezone instances should normally only be constructed when
|
30
|
+
# creating new DataSource implementations.
|
31
|
+
def new(identifier, latitude, longitude, description = nil)
|
32
|
+
super(identifier, latitude, nil, longitude, nil, description)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Creates a new CountryTimezone with a timezone identifier, latitude,
|
37
|
+
# longitude and description. The latitude and longitude are specified as
|
38
|
+
# rationals - a numerator and denominator. For performance reasons, the
|
39
|
+
# numerators and denominators must be specified in their lowest form.
|
40
|
+
#
|
41
|
+
# @!visibility private
|
42
|
+
def initialize(identifier, latitude_numerator, latitude_denominator,
|
43
|
+
longitude_numerator, longitude_denominator, description = nil) #:nodoc:
|
44
|
+
@identifier = identifier
|
45
|
+
|
46
|
+
if latitude_numerator.kind_of?(Rational)
|
47
|
+
@latitude = latitude_numerator
|
48
|
+
else
|
49
|
+
@latitude = nil
|
50
|
+
@latitude_numerator = latitude_numerator
|
51
|
+
@latitude_denominator = latitude_denominator
|
52
|
+
end
|
53
|
+
|
54
|
+
if longitude_numerator.kind_of?(Rational)
|
55
|
+
@longitude = longitude_numerator
|
56
|
+
else
|
57
|
+
@longitude = nil
|
58
|
+
@longitude_numerator = longitude_numerator
|
59
|
+
@longitude_denominator = longitude_denominator
|
60
|
+
end
|
61
|
+
|
62
|
+
@description = description
|
63
|
+
end
|
64
|
+
|
65
|
+
# The Timezone (actually a TimezoneProxy for performance reasons).
|
66
|
+
def timezone
|
67
|
+
Timezone.get_proxy(@identifier)
|
68
|
+
end
|
69
|
+
|
70
|
+
# if description is not nil, this method returns description; otherwise it
|
71
|
+
# returns timezone.friendly_identifier(true).
|
72
|
+
def description_or_friendly_identifier
|
73
|
+
description || timezone.friendly_identifier(true)
|
74
|
+
end
|
75
|
+
|
76
|
+
# The latitude of this timezone in degrees as a Rational.
|
77
|
+
def latitude
|
78
|
+
# Thread-safety: It is possible that the value of @latitude may be
|
79
|
+
# calculated multiple times in concurrently executing threads. It is not
|
80
|
+
# worth the overhead of locking to ensure that @latitude is only
|
81
|
+
# calculated once.
|
82
|
+
unless @latitude
|
83
|
+
result = RubyCoreSupport.rational_new!(@latitude_numerator, @latitude_denominator)
|
84
|
+
return result if frozen?
|
85
|
+
@latitude = result
|
86
|
+
end
|
87
|
+
|
88
|
+
@latitude
|
89
|
+
end
|
90
|
+
|
91
|
+
# The longitude of this timezone in degrees as a Rational.
|
92
|
+
def longitude
|
93
|
+
# Thread-safety: It is possible that the value of @longitude may be
|
94
|
+
# calculated multiple times in concurrently executing threads. It is not
|
95
|
+
# worth the overhead of locking to ensure that @longitude is only
|
96
|
+
# calculated once.
|
97
|
+
unless @longitude
|
98
|
+
result = RubyCoreSupport.rational_new!(@longitude_numerator, @longitude_denominator)
|
99
|
+
return result if frozen?
|
100
|
+
@longitude = result
|
101
|
+
end
|
102
|
+
|
103
|
+
@longitude
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns true if and only if the given CountryTimezone is equal to the
|
107
|
+
# current CountryTimezone (has the same identifer, latitude, longitude
|
108
|
+
# and description).
|
109
|
+
def ==(ct)
|
110
|
+
ct.kind_of?(CountryTimezone) &&
|
111
|
+
identifier == ct.identifier && latitude == ct.latitude &&
|
112
|
+
longitude == ct.longitude && description == ct.description
|
113
|
+
end
|
114
|
+
|
115
|
+
# Returns true if and only if the given CountryTimezone is equal to the
|
116
|
+
# current CountryTimezone (has the same identifer, latitude, longitude
|
117
|
+
# and description).
|
118
|
+
def eql?(ct)
|
119
|
+
self == ct
|
120
|
+
end
|
121
|
+
|
122
|
+
# Returns a hash of this CountryTimezone.
|
123
|
+
def hash
|
124
|
+
@identifier.hash ^
|
125
|
+
(@latitude ? @latitude.numerator.hash ^ @latitude.denominator.hash : @latitude_numerator.hash ^ @latitude_denominator.hash) ^
|
126
|
+
(@longitude ? @longitude.numerator.hash ^ @longitude.denominator.hash : @longitude_numerator.hash ^ @longitude_denominator.hash) ^
|
127
|
+
@description.hash
|
128
|
+
end
|
129
|
+
|
130
|
+
# Returns internal object state as a programmer-readable string.
|
131
|
+
def inspect
|
132
|
+
"#<#{self.class}: #@identifier>"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
3
|
+
module TZInfo
|
4
|
+
# InvalidDataSource is raised if the DataSource is used doesn't implement one
|
5
|
+
# of the required methods.
|
6
|
+
class InvalidDataSource < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
# DataSourceNotFound is raised if no data source could be found (i.e.
|
10
|
+
# if 'tzinfo/data' cannot be found on the load path and no valid zoneinfo
|
11
|
+
# directory can be found on the system).
|
12
|
+
class DataSourceNotFound < StandardError
|
13
|
+
end
|
14
|
+
|
15
|
+
# The base class for data sources of timezone and country data.
|
16
|
+
#
|
17
|
+
# Use DataSource.set to change the data source being used.
|
18
|
+
class DataSource
|
19
|
+
# The currently selected data source.
|
20
|
+
@@instance = nil
|
21
|
+
|
22
|
+
# Mutex used to ensure the default data source is only created once.
|
23
|
+
@@default_mutex = Mutex.new
|
24
|
+
|
25
|
+
# Returns the currently selected DataSource instance.
|
26
|
+
def self.get
|
27
|
+
# If a DataSource hasn't been manually set when the first request is
|
28
|
+
# made to obtain a DataSource, then a Default data source is created.
|
29
|
+
|
30
|
+
# This is done at the first request rather than when TZInfo is loaded to
|
31
|
+
# avoid unnecessary (or in some cases potentially harmful) attempts to
|
32
|
+
# find a suitable DataSource.
|
33
|
+
|
34
|
+
# A Mutex is used to ensure that only a single default instance is
|
35
|
+
# created (having two different DataSources in use simultaneously could
|
36
|
+
# cause unexpected results).
|
37
|
+
|
38
|
+
unless @@instance
|
39
|
+
@@default_mutex.synchronize do
|
40
|
+
set(create_default_data_source) unless @@instance
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
@@instance
|
45
|
+
end
|
46
|
+
|
47
|
+
# Sets the currently selected data source for Timezone and Country data.
|
48
|
+
#
|
49
|
+
# This should usually be set to one of the two standard data source types:
|
50
|
+
#
|
51
|
+
# * +:ruby+ - read data from the Ruby modules included in the TZInfo::Data
|
52
|
+
# library (tzinfo-data gem).
|
53
|
+
# * +:zoneinfo+ - read data from the zoneinfo files included with most
|
54
|
+
# Unix-like operating sytems (e.g. in /usr/share/zoneinfo).
|
55
|
+
#
|
56
|
+
# To set TZInfo to use one of the standard data source types, call
|
57
|
+
# \TZInfo::DataSource.set in one of the following ways:
|
58
|
+
#
|
59
|
+
# TZInfo::DataSource.set(:ruby)
|
60
|
+
# TZInfo::DataSource.set(:zoneinfo)
|
61
|
+
# TZInfo::DataSource.set(:zoneinfo, zoneinfo_dir)
|
62
|
+
# TZInfo::DataSource.set(:zoneinfo, zoneinfo_dir, iso3166_tab_file)
|
63
|
+
#
|
64
|
+
# \DataSource.set(:zoneinfo) will automatically search for the zoneinfo
|
65
|
+
# directory by checking the paths specified in
|
66
|
+
# ZoneinfoDataSource.search_paths. ZoneinfoDirectoryNotFound will be raised
|
67
|
+
# if no valid zoneinfo directory could be found.
|
68
|
+
#
|
69
|
+
# \DataSource.set(:zoneinfo, zoneinfo_dir) uses the specified zoneinfo
|
70
|
+
# directory as the data source. If the directory is not a valid zoneinfo
|
71
|
+
# directory, an InvalidZoneinfoDirectory exception will be raised.
|
72
|
+
#
|
73
|
+
# \DataSource.set(:zoneinfo, zoneinfo_dir, iso3166_tab_file) uses the
|
74
|
+
# specified zoneinfo directory as the data source, but loads the iso3166.tab
|
75
|
+
# file from an alternate path. If the directory is not a valid zoneinfo
|
76
|
+
# directory, an InvalidZoneinfoDirectory exception will be raised.
|
77
|
+
#
|
78
|
+
# Custom data sources can be created by subclassing TZInfo::DataSource and
|
79
|
+
# implementing the following methods:
|
80
|
+
#
|
81
|
+
# * \load_timezone_info
|
82
|
+
# * \timezone_identifiers
|
83
|
+
# * \data_timezone_identifiers
|
84
|
+
# * \linked_timezone_identifiers
|
85
|
+
# * \load_country_info
|
86
|
+
# * \country_codes
|
87
|
+
#
|
88
|
+
# To have TZInfo use the custom data source, call \DataSource.set
|
89
|
+
# as follows:
|
90
|
+
#
|
91
|
+
# TZInfo::DataSource.set(CustomDataSource.new)
|
92
|
+
#
|
93
|
+
# To avoid inconsistent data, \DataSource.set should be called before
|
94
|
+
# accessing any Timezone or Country data.
|
95
|
+
#
|
96
|
+
# If \DataSource.set is not called, TZInfo will by default use TZInfo::Data
|
97
|
+
# as the data source. If TZInfo::Data is not available (i.e. if require
|
98
|
+
# 'tzinfo/data' fails), then TZInfo will search for a zoneinfo directory
|
99
|
+
# instead (using the search path specified by
|
100
|
+
# TZInfo::ZoneinfoDataSource::DEFAULT_SEARCH_PATH).
|
101
|
+
def self.set(data_source_or_type, *args)
|
102
|
+
if data_source_or_type.kind_of?(DataSource)
|
103
|
+
@@instance = data_source_or_type
|
104
|
+
elsif data_source_or_type == :ruby
|
105
|
+
@@instance = RubyDataSource.new
|
106
|
+
elsif data_source_or_type == :zoneinfo
|
107
|
+
@@instance = ZoneinfoDataSource.new(*args)
|
108
|
+
else
|
109
|
+
raise ArgumentError, 'data_source_or_type must be a DataSource instance or a data source type (:ruby)'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Returns a TimezoneInfo instance for a given identifier. The TimezoneInfo
|
114
|
+
# instance should derive from either DataTimzoneInfo for timezones that
|
115
|
+
# define their own data or LinkedTimezoneInfo for links or aliases to
|
116
|
+
# other timezones.
|
117
|
+
#
|
118
|
+
# Raises InvalidTimezoneIdentifier if the timezone is not found or the
|
119
|
+
# identifier is invalid.
|
120
|
+
def load_timezone_info(identifier)
|
121
|
+
raise_invalid_data_source('load_timezone_info')
|
122
|
+
end
|
123
|
+
|
124
|
+
# Returns an array of all the available timezone identifiers.
|
125
|
+
def timezone_identifiers
|
126
|
+
raise_invalid_data_source('timezone_identifiers')
|
127
|
+
end
|
128
|
+
|
129
|
+
# Returns an array of all the available timezone identifiers for
|
130
|
+
# data timezones (i.e. those that actually contain definitions).
|
131
|
+
def data_timezone_identifiers
|
132
|
+
raise_invalid_data_source('data_timezone_identifiers')
|
133
|
+
end
|
134
|
+
|
135
|
+
# Returns an array of all the available timezone identifiers that
|
136
|
+
# are links to other timezones.
|
137
|
+
def linked_timezone_identifiers
|
138
|
+
raise_invalid_data_source('linked_timezone_identifiers')
|
139
|
+
end
|
140
|
+
|
141
|
+
# Returns a CountryInfo instance for the given ISO 3166-1 alpha-2
|
142
|
+
# country code. Raises InvalidCountryCode if the country could not be found
|
143
|
+
# or the code is invalid.
|
144
|
+
def load_country_info(code)
|
145
|
+
raise_invalid_data_source('load_country_info')
|
146
|
+
end
|
147
|
+
|
148
|
+
# Returns an array of all the available ISO 3166-1 alpha-2
|
149
|
+
# country codes.
|
150
|
+
def country_codes
|
151
|
+
raise_invalid_data_source('country_codes')
|
152
|
+
end
|
153
|
+
|
154
|
+
# Returns the name of this DataSource.
|
155
|
+
def to_s
|
156
|
+
"Default DataSource"
|
157
|
+
end
|
158
|
+
|
159
|
+
# Returns internal object state as a programmer-readable string.
|
160
|
+
def inspect
|
161
|
+
"#<#{self.class}>"
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
# Creates a DataSource instance for use as the default. Used if
|
167
|
+
# no preference has been specified manually.
|
168
|
+
def self.create_default_data_source
|
169
|
+
has_tzinfo_data = false
|
170
|
+
|
171
|
+
begin
|
172
|
+
require 'tzinfo/data'
|
173
|
+
has_tzinfo_data = true
|
174
|
+
rescue LoadError
|
175
|
+
end
|
176
|
+
|
177
|
+
return RubyDataSource.new if has_tzinfo_data
|
178
|
+
|
179
|
+
begin
|
180
|
+
return ZoneinfoDataSource.new
|
181
|
+
rescue ZoneinfoDirectoryNotFound
|
182
|
+
raise DataSourceNotFound, "No source of timezone data could be found.\nPlease refer to http://tzinfo.github.io/datasourcenotfound for help resolving this error."
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def raise_invalid_data_source(method_name)
|
187
|
+
raise InvalidDataSource, "#{method_name} not defined"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module TZInfo
|
2
|
+
|
3
|
+
# A Timezone based on a DataTimezoneInfo.
|
4
|
+
#
|
5
|
+
# @private
|
6
|
+
class DataTimezone < InfoTimezone #:nodoc:
|
7
|
+
|
8
|
+
# Returns the TimezonePeriod for the given UTC time. utc can either be
|
9
|
+
# a DateTime, Time or integer timestamp (Time.to_i). Any timezone
|
10
|
+
# information in utc is ignored (it is treated as a UTC time).
|
11
|
+
#
|
12
|
+
# If no TimezonePeriod could be found, PeriodNotFound is raised.
|
13
|
+
def period_for_utc(utc)
|
14
|
+
info.period_for_utc(utc)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the set of TimezonePeriod instances that are valid for the given
|
18
|
+
# local time as an array. If you just want a single period, use
|
19
|
+
# period_for_local instead and specify how abiguities should be resolved.
|
20
|
+
# Raises PeriodNotFound if no periods are found for the given time.
|
21
|
+
def periods_for_local(local)
|
22
|
+
info.periods_for_local(local)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns an Array of TimezoneTransition instances representing the times
|
26
|
+
# where the UTC offset of the timezone changes.
|
27
|
+
#
|
28
|
+
# Transitions are returned up to a given date and time up to a given date
|
29
|
+
# and time, specified in UTC (utc_to).
|
30
|
+
#
|
31
|
+
# A from date and time may also be supplied using the utc_from parameter
|
32
|
+
# (also specified in UTC). If utc_from is not nil, only transitions from
|
33
|
+
# that date and time onwards will be returned.
|
34
|
+
#
|
35
|
+
# Comparisons with utc_to are exclusive. Comparisons with utc_from are
|
36
|
+
# inclusive. If a transition falls precisely on utc_to, it will be excluded.
|
37
|
+
# If a transition falls on utc_from, it will be included.
|
38
|
+
#
|
39
|
+
# Transitions returned are ordered by when they occur, from earliest to
|
40
|
+
# latest.
|
41
|
+
#
|
42
|
+
# utc_to and utc_from can be specified using either DateTime, Time or
|
43
|
+
# integer timestamps (Time.to_i).
|
44
|
+
#
|
45
|
+
# If utc_from is specified and utc_to is not greater than utc_from, then
|
46
|
+
# transitions_up_to raises an ArgumentError exception.
|
47
|
+
def transitions_up_to(utc_to, utc_from = nil)
|
48
|
+
info.transitions_up_to(utc_to, utc_from)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the canonical zone for this Timezone.
|
52
|
+
#
|
53
|
+
# For a DataTimezone, this is always self.
|
54
|
+
def canonical_zone
|
55
|
+
self
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|