tzinfo 1.2.10 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.yardopts +3 -0
- data/CHANGES.md +583 -391
- data/LICENSE +13 -13
- data/README.md +368 -114
- data/lib/tzinfo/annual_rules.rb +32 -12
- data/lib/tzinfo/country.rb +141 -129
- data/lib/tzinfo/country_timezone.rb +70 -112
- data/lib/tzinfo/data_source.rb +400 -144
- data/lib/tzinfo/data_sources/constant_offset_data_timezone_info.rb +56 -0
- data/lib/tzinfo/data_sources/country_info.rb +42 -0
- data/lib/tzinfo/data_sources/data_timezone_info.rb +91 -0
- data/lib/tzinfo/data_sources/linked_timezone_info.rb +33 -0
- data/lib/tzinfo/data_sources/posix_time_zone_parser.rb +177 -0
- data/lib/tzinfo/data_sources/ruby_data_source.rb +141 -0
- data/lib/tzinfo/data_sources/timezone_info.rb +47 -0
- data/lib/tzinfo/data_sources/transitions_data_timezone_info.rb +214 -0
- data/lib/tzinfo/data_sources/zoneinfo_data_source.rb +592 -0
- data/lib/tzinfo/data_sources/zoneinfo_reader.rb +482 -0
- data/lib/tzinfo/data_sources.rb +8 -0
- data/lib/tzinfo/data_timezone.rb +33 -47
- data/lib/tzinfo/datetime_with_offset.rb +153 -0
- data/lib/tzinfo/format1/country_definer.rb +17 -0
- data/lib/tzinfo/format1/country_index_definition.rb +64 -0
- data/lib/tzinfo/format1/timezone_definer.rb +64 -0
- data/lib/tzinfo/format1/timezone_definition.rb +39 -0
- data/lib/tzinfo/format1/timezone_index_definition.rb +77 -0
- data/lib/tzinfo/format1.rb +10 -0
- data/lib/tzinfo/format2/country_definer.rb +68 -0
- data/lib/tzinfo/format2/country_index_definer.rb +68 -0
- data/lib/tzinfo/format2/country_index_definition.rb +46 -0
- data/lib/tzinfo/format2/timezone_definer.rb +94 -0
- data/lib/tzinfo/format2/timezone_definition.rb +73 -0
- data/lib/tzinfo/format2/timezone_index_definer.rb +45 -0
- data/lib/tzinfo/format2/timezone_index_definition.rb +55 -0
- data/lib/tzinfo/format2.rb +10 -0
- data/lib/tzinfo/info_timezone.rb +26 -21
- data/lib/tzinfo/linked_timezone.rb +33 -52
- data/lib/tzinfo/offset_timezone_period.rb +42 -0
- data/lib/tzinfo/ruby_core_support.rb +24 -155
- data/lib/tzinfo/string_deduper.rb +118 -0
- data/lib/tzinfo/time_with_offset.rb +154 -0
- data/lib/tzinfo/timestamp.rb +552 -0
- data/lib/tzinfo/timestamp_with_offset.rb +85 -0
- data/lib/tzinfo/timezone.rb +989 -502
- data/lib/tzinfo/timezone_offset.rb +84 -74
- data/lib/tzinfo/timezone_period.rb +151 -217
- data/lib/tzinfo/timezone_proxy.rb +70 -79
- data/lib/tzinfo/timezone_transition.rb +77 -109
- data/lib/tzinfo/transition_rule.rb +207 -77
- data/lib/tzinfo/transitions_timezone_period.rb +63 -0
- data/lib/tzinfo/version.rb +7 -0
- data/lib/tzinfo/with_offset.rb +61 -0
- data/lib/tzinfo.rb +78 -40
- data.tar.gz.sig +0 -0
- metadata +50 -105
- metadata.gz.sig +0 -0
- data/Rakefile +0 -107
- data/lib/tzinfo/country_index_definition.rb +0 -31
- data/lib/tzinfo/country_info.rb +0 -42
- data/lib/tzinfo/data_timezone_info.rb +0 -55
- data/lib/tzinfo/linked_timezone_info.rb +0 -26
- data/lib/tzinfo/offset_rationals.rb +0 -77
- data/lib/tzinfo/posix_time_zone_parser.rb +0 -136
- data/lib/tzinfo/ruby_country_info.rb +0 -74
- data/lib/tzinfo/ruby_data_source.rb +0 -140
- data/lib/tzinfo/time_or_datetime.rb +0 -351
- data/lib/tzinfo/timezone_definition.rb +0 -36
- data/lib/tzinfo/timezone_index_definition.rb +0 -54
- data/lib/tzinfo/timezone_info.rb +0 -30
- data/lib/tzinfo/timezone_transition_definition.rb +0 -104
- data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
- data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
- data/lib/tzinfo/zoneinfo_data_source.rb +0 -512
- data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -520
- data/test/assets/payload.rb +0 -1
- data/test/tc_annual_rules.rb +0 -95
- data/test/tc_country.rb +0 -238
- data/test/tc_country_index_definition.rb +0 -69
- data/test/tc_country_info.rb +0 -16
- data/test/tc_country_timezone.rb +0 -173
- data/test/tc_data_source.rb +0 -218
- data/test/tc_data_timezone.rb +0 -99
- data/test/tc_data_timezone_info.rb +0 -18
- data/test/tc_info_timezone.rb +0 -34
- data/test/tc_linked_timezone.rb +0 -155
- data/test/tc_linked_timezone_info.rb +0 -23
- data/test/tc_offset_rationals.rb +0 -23
- data/test/tc_posix_time_zone_parser.rb +0 -261
- data/test/tc_ruby_core_support.rb +0 -168
- data/test/tc_ruby_country_info.rb +0 -110
- data/test/tc_ruby_data_source.rb +0 -173
- data/test/tc_time_or_datetime.rb +0 -674
- data/test/tc_timezone.rb +0 -1361
- data/test/tc_timezone_definition.rb +0 -113
- data/test/tc_timezone_index_definition.rb +0 -73
- data/test/tc_timezone_info.rb +0 -11
- data/test/tc_timezone_london.rb +0 -143
- data/test/tc_timezone_melbourne.rb +0 -142
- data/test/tc_timezone_new_york.rb +0 -142
- data/test/tc_timezone_offset.rb +0 -126
- data/test/tc_timezone_period.rb +0 -555
- data/test/tc_timezone_proxy.rb +0 -136
- data/test/tc_timezone_transition.rb +0 -366
- data/test/tc_timezone_transition_definition.rb +0 -295
- data/test/tc_timezone_utc.rb +0 -27
- data/test/tc_transition_data_timezone_info.rb +0 -433
- data/test/tc_transition_rule.rb +0 -663
- data/test/tc_zoneinfo_country_info.rb +0 -78
- data/test/tc_zoneinfo_data_source.rb +0 -1223
- data/test/tc_zoneinfo_timezone_info.rb +0 -2153
- data/test/test_utils.rb +0 -208
- data/test/ts_all.rb +0 -7
- data/test/ts_all_ruby.rb +0 -5
- data/test/ts_all_zoneinfo.rb +0 -9
- data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +0 -89
- data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -327
- data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -230
- data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +0 -19
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +0 -273
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -198
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -333
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -277
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -235
- data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
- data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -940
- data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -609
- data/test/tzinfo-data/tzinfo/data/version.rb +0 -20
- data/test/tzinfo-data/tzinfo/data.rb +0 -8
- 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 +0 -274
- data/test/zoneinfo/leapseconds +0 -78
- 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 +0 -452
- data/test/zoneinfo/zone1970.tab +0 -384
- data/tzinfo.gemspec +0 -21
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'rational' unless defined?(Rational)
|
2
|
-
|
3
|
-
module TZInfo
|
4
|
-
|
5
|
-
# Provides a method for getting Rationals for a timezone offset in seconds.
|
6
|
-
# Pre-reduced rationals are returned for all the half-hour intervals between
|
7
|
-
# -14 and +14 hours to avoid having to call gcd at runtime.
|
8
|
-
#
|
9
|
-
# @private
|
10
|
-
module OffsetRationals #:nodoc:
|
11
|
-
@@rational_cache = {
|
12
|
-
-50400 => RubyCoreSupport.rational_new!(-7,12),
|
13
|
-
-48600 => RubyCoreSupport.rational_new!(-9,16),
|
14
|
-
-46800 => RubyCoreSupport.rational_new!(-13,24),
|
15
|
-
-45000 => RubyCoreSupport.rational_new!(-25,48),
|
16
|
-
-43200 => RubyCoreSupport.rational_new!(-1,2),
|
17
|
-
-41400 => RubyCoreSupport.rational_new!(-23,48),
|
18
|
-
-39600 => RubyCoreSupport.rational_new!(-11,24),
|
19
|
-
-37800 => RubyCoreSupport.rational_new!(-7,16),
|
20
|
-
-36000 => RubyCoreSupport.rational_new!(-5,12),
|
21
|
-
-34200 => RubyCoreSupport.rational_new!(-19,48),
|
22
|
-
-32400 => RubyCoreSupport.rational_new!(-3,8),
|
23
|
-
-30600 => RubyCoreSupport.rational_new!(-17,48),
|
24
|
-
-28800 => RubyCoreSupport.rational_new!(-1,3),
|
25
|
-
-27000 => RubyCoreSupport.rational_new!(-5,16),
|
26
|
-
-25200 => RubyCoreSupport.rational_new!(-7,24),
|
27
|
-
-23400 => RubyCoreSupport.rational_new!(-13,48),
|
28
|
-
-21600 => RubyCoreSupport.rational_new!(-1,4),
|
29
|
-
-19800 => RubyCoreSupport.rational_new!(-11,48),
|
30
|
-
-18000 => RubyCoreSupport.rational_new!(-5,24),
|
31
|
-
-16200 => RubyCoreSupport.rational_new!(-3,16),
|
32
|
-
-14400 => RubyCoreSupport.rational_new!(-1,6),
|
33
|
-
-12600 => RubyCoreSupport.rational_new!(-7,48),
|
34
|
-
-10800 => RubyCoreSupport.rational_new!(-1,8),
|
35
|
-
-9000 => RubyCoreSupport.rational_new!(-5,48),
|
36
|
-
-7200 => RubyCoreSupport.rational_new!(-1,12),
|
37
|
-
-5400 => RubyCoreSupport.rational_new!(-1,16),
|
38
|
-
-3600 => RubyCoreSupport.rational_new!(-1,24),
|
39
|
-
-1800 => RubyCoreSupport.rational_new!(-1,48),
|
40
|
-
0 => RubyCoreSupport.rational_new!(0,1),
|
41
|
-
1800 => RubyCoreSupport.rational_new!(1,48),
|
42
|
-
3600 => RubyCoreSupport.rational_new!(1,24),
|
43
|
-
5400 => RubyCoreSupport.rational_new!(1,16),
|
44
|
-
7200 => RubyCoreSupport.rational_new!(1,12),
|
45
|
-
9000 => RubyCoreSupport.rational_new!(5,48),
|
46
|
-
10800 => RubyCoreSupport.rational_new!(1,8),
|
47
|
-
12600 => RubyCoreSupport.rational_new!(7,48),
|
48
|
-
14400 => RubyCoreSupport.rational_new!(1,6),
|
49
|
-
16200 => RubyCoreSupport.rational_new!(3,16),
|
50
|
-
18000 => RubyCoreSupport.rational_new!(5,24),
|
51
|
-
19800 => RubyCoreSupport.rational_new!(11,48),
|
52
|
-
21600 => RubyCoreSupport.rational_new!(1,4),
|
53
|
-
23400 => RubyCoreSupport.rational_new!(13,48),
|
54
|
-
25200 => RubyCoreSupport.rational_new!(7,24),
|
55
|
-
27000 => RubyCoreSupport.rational_new!(5,16),
|
56
|
-
28800 => RubyCoreSupport.rational_new!(1,3),
|
57
|
-
30600 => RubyCoreSupport.rational_new!(17,48),
|
58
|
-
32400 => RubyCoreSupport.rational_new!(3,8),
|
59
|
-
34200 => RubyCoreSupport.rational_new!(19,48),
|
60
|
-
36000 => RubyCoreSupport.rational_new!(5,12),
|
61
|
-
37800 => RubyCoreSupport.rational_new!(7,16),
|
62
|
-
39600 => RubyCoreSupport.rational_new!(11,24),
|
63
|
-
41400 => RubyCoreSupport.rational_new!(23,48),
|
64
|
-
43200 => RubyCoreSupport.rational_new!(1,2),
|
65
|
-
45000 => RubyCoreSupport.rational_new!(25,48),
|
66
|
-
46800 => RubyCoreSupport.rational_new!(13,24),
|
67
|
-
48600 => RubyCoreSupport.rational_new!(9,16),
|
68
|
-
50400 => RubyCoreSupport.rational_new!(7,12)}.freeze
|
69
|
-
|
70
|
-
# Returns a Rational expressing the fraction of a day that offset in
|
71
|
-
# seconds represents (i.e. equivalent to Rational(offset, 86400)).
|
72
|
-
def rational_for_offset(offset)
|
73
|
-
@@rational_cache[offset] || Rational(offset, 86400)
|
74
|
-
end
|
75
|
-
module_function :rational_for_offset
|
76
|
-
end
|
77
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'strscan'
|
5
|
-
|
6
|
-
module TZInfo
|
7
|
-
# An {InvalidPosixTimeZone} exception is raised if an invalid POSIX-style
|
8
|
-
# time zone string is encountered.
|
9
|
-
#
|
10
|
-
# @private
|
11
|
-
class InvalidPosixTimeZone < StandardError #:nodoc:
|
12
|
-
end
|
13
|
-
|
14
|
-
# A parser for POSIX-style TZ strings used in zoneinfo files and specified
|
15
|
-
# by tzfile.5 and tzset.3.
|
16
|
-
#
|
17
|
-
# @private
|
18
|
-
class PosixTimeZoneParser #:nodoc:
|
19
|
-
# Parses a POSIX-style TZ string, returning either a TimezoneOffset or
|
20
|
-
# an AnnualRules instance.
|
21
|
-
def parse(tz_string)
|
22
|
-
raise InvalidPosixTimeZone unless tz_string.kind_of?(String)
|
23
|
-
return nil if tz_string.empty?
|
24
|
-
|
25
|
-
s = StringScanner.new(tz_string)
|
26
|
-
check_scan(s, /([^-+,\d<][^-+,\d]*) | <([^>]+)>/x)
|
27
|
-
std_abbrev = s[1] || s[2]
|
28
|
-
check_scan(s, /([-+]?\d+)(?::(\d+)(?::(\d+))?)?/)
|
29
|
-
std_offset = get_offset_from_hms(s[1], s[2], s[3])
|
30
|
-
|
31
|
-
if s.scan(/([^-+,\d<][^-+,\d]*) | <([^>]+)>/x)
|
32
|
-
dst_abbrev = s[1] || s[2]
|
33
|
-
|
34
|
-
if s.scan(/([-+]?\d+)(?::(\d+)(?::(\d+))?)?/)
|
35
|
-
dst_offset = get_offset_from_hms(s[1], s[2], s[3])
|
36
|
-
else
|
37
|
-
# POSIX is negative for ahead of UTC.
|
38
|
-
dst_offset = std_offset - 3600
|
39
|
-
end
|
40
|
-
|
41
|
-
dst_difference = std_offset - dst_offset
|
42
|
-
|
43
|
-
start_rule = parse_rule(s, 'start')
|
44
|
-
end_rule = parse_rule(s, 'end')
|
45
|
-
|
46
|
-
raise InvalidPosixTimeZone, "Expected the end of a POSIX-style time zone string but found '#{s.rest}'." if s.rest?
|
47
|
-
|
48
|
-
if start_rule.is_always_first_day_of_year? && start_rule.transition_at == 0 &&
|
49
|
-
end_rule.is_always_last_day_of_year? && end_rule.transition_at == 86400 + dst_difference
|
50
|
-
# Constant daylight savings time.
|
51
|
-
# POSIX is negative for ahead of UTC.
|
52
|
-
TimezoneOffset.new(-std_offset, dst_difference, dst_abbrev.to_sym)
|
53
|
-
else
|
54
|
-
AnnualRules.new(
|
55
|
-
TimezoneOffset.new(-std_offset, 0, std_abbrev.to_sym),
|
56
|
-
TimezoneOffset.new(-std_offset, dst_difference, dst_abbrev.to_sym),
|
57
|
-
start_rule,
|
58
|
-
end_rule)
|
59
|
-
end
|
60
|
-
elsif !s.rest?
|
61
|
-
# Constant standard time.
|
62
|
-
# POSIX is negative for ahead of UTC.
|
63
|
-
TimezoneOffset.new(-std_offset, 0, std_abbrev.to_sym)
|
64
|
-
else
|
65
|
-
raise InvalidPosixTimeZone, "Expected the end of a POSIX-style time zone string but found '#{s.rest}'."
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
# Parses the rule from the TZ string, returning a TransitionRule.
|
72
|
-
def parse_rule(s, type)
|
73
|
-
check_scan(s, /,(?: (?: J(\d+) ) | (\d+) | (?: M(\d+)\.(\d)\.(\d) ) )/x)
|
74
|
-
julian_day_of_year = s[1]
|
75
|
-
absolute_day_of_year = s[2]
|
76
|
-
month = s[3]
|
77
|
-
week = s[4]
|
78
|
-
day_of_week = s[5]
|
79
|
-
|
80
|
-
if s.scan(/\//)
|
81
|
-
check_scan(s, /([-+]?\d+)(?::(\d+)(?::(\d+))?)?/)
|
82
|
-
transition_at = get_seconds_after_midnight_from_hms(s[1], s[2], s[3])
|
83
|
-
else
|
84
|
-
transition_at = 7200
|
85
|
-
end
|
86
|
-
|
87
|
-
begin
|
88
|
-
if julian_day_of_year
|
89
|
-
JulianDayOfYearTransitionRule.new(julian_day_of_year.to_i, transition_at)
|
90
|
-
elsif absolute_day_of_year
|
91
|
-
AbsoluteDayOfYearTransitionRule.new(absolute_day_of_year.to_i, transition_at)
|
92
|
-
elsif week == '5'
|
93
|
-
LastDayOfMonthTransitionRule.new(month.to_i, day_of_week.to_i, transition_at)
|
94
|
-
else
|
95
|
-
DayOfMonthTransitionRule.new(month.to_i, week.to_i, day_of_week.to_i, transition_at)
|
96
|
-
end
|
97
|
-
rescue ArgumentError => e
|
98
|
-
raise InvalidPosixTimeZone, "Invalid #{type} rule in POSIX-style time zone string: #{e}"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# Returns an offset in seconds from hh:mm:ss values. The value can be
|
103
|
-
# negative. -02:33:12 would represent 2 hours, 33 minutes and 12 seconds
|
104
|
-
# ahead of UTC.
|
105
|
-
def get_offset_from_hms(h, m, s)
|
106
|
-
h = h.to_i
|
107
|
-
m = m.to_i
|
108
|
-
s = s.to_i
|
109
|
-
raise InvalidPosixTimeZone, "Invalid minute #{m} in offset for POSIX-style time zone string." if m > 59
|
110
|
-
raise InvalidPosixTimeZone, "Invalid second #{s} in offset for POSIX-style time zone string." if s > 59
|
111
|
-
magnitude = (h.abs * 60 + m) * 60 + s
|
112
|
-
h < 0 ? -magnitude : magnitude
|
113
|
-
end
|
114
|
-
|
115
|
-
# Returns the seconds from midnight from hh:mm:ss values. Hours can exceed
|
116
|
-
# 24 for a time on the following day. Hours can be negative to subtract
|
117
|
-
# hours from midnight on the given day. -02:33:12 represents 22:33:12 on
|
118
|
-
# the prior day.
|
119
|
-
def get_seconds_after_midnight_from_hms(h, m, s)
|
120
|
-
h = h.to_i
|
121
|
-
m = m.to_i
|
122
|
-
s = s.to_i
|
123
|
-
raise InvalidPosixTimeZone, "Invalid minute #{m} in time for POSIX-style time zone string." if m > 59
|
124
|
-
raise InvalidPosixTimeZone, "Invalid second #{s} in time for POSIX-style time zone string." if s > 59
|
125
|
-
(h * 3600) + m * 60 + s
|
126
|
-
end
|
127
|
-
|
128
|
-
# Scans for a pattern and raises an exception if the pattern does not
|
129
|
-
# match the input.
|
130
|
-
def check_scan(s, pattern)
|
131
|
-
result = s.scan(pattern)
|
132
|
-
raise InvalidPosixTimeZone, "Expected '#{s.rest}' to match #{pattern} in POSIX-style time zone string." unless result
|
133
|
-
result
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
module TZInfo
|
2
|
-
# Represents information about a country returned by RubyDataSource.
|
3
|
-
#
|
4
|
-
# @private
|
5
|
-
class RubyCountryInfo < CountryInfo #:nodoc:
|
6
|
-
# Constructs a new CountryInfo with an ISO 3166 country code, name and
|
7
|
-
# block. The block will be evaluated to obtain the timezones for the
|
8
|
-
# country when the zones are first needed.
|
9
|
-
def initialize(code, name, &block)
|
10
|
-
super(code, name)
|
11
|
-
@block = block
|
12
|
-
@zones = nil
|
13
|
-
@zone_identifiers = nil
|
14
|
-
end
|
15
|
-
|
16
|
-
# Returns a frozen array of all the zone identifiers for the country. These
|
17
|
-
# are in the order they were added using the timezone method.
|
18
|
-
def zone_identifiers
|
19
|
-
# Thread-safety: It is possible that the value of @zone_identifiers may be
|
20
|
-
# calculated multiple times in concurrently executing threads. It is not
|
21
|
-
# worth the overhead of locking to ensure that @zone_identifiers is only
|
22
|
-
# calculated once.
|
23
|
-
|
24
|
-
unless @zone_identifiers
|
25
|
-
result = zones.collect {|zone| zone.identifier}.freeze
|
26
|
-
return result if frozen?
|
27
|
-
@zone_identifiers = result
|
28
|
-
end
|
29
|
-
|
30
|
-
@zone_identifiers
|
31
|
-
end
|
32
|
-
|
33
|
-
# Returns a frozen array of all the timezones for the for the country as
|
34
|
-
# CountryTimezone instances. These are in the order they were added using
|
35
|
-
# the timezone method.
|
36
|
-
def zones
|
37
|
-
# Thread-safety: It is possible that the value of @zones may be
|
38
|
-
# calculated multiple times in concurrently executing threads. It is not
|
39
|
-
# worth the overhead of locking to ensure that @zones is only
|
40
|
-
# calculated once.
|
41
|
-
|
42
|
-
unless @zones
|
43
|
-
zones = Zones.new
|
44
|
-
@block.call(zones) if @block
|
45
|
-
result = zones.list.freeze
|
46
|
-
return result if frozen?
|
47
|
-
@block = nil
|
48
|
-
@zones = result
|
49
|
-
end
|
50
|
-
|
51
|
-
@zones
|
52
|
-
end
|
53
|
-
|
54
|
-
# An instance of the Zones class is passed to the block used to define
|
55
|
-
# timezones.
|
56
|
-
#
|
57
|
-
# @private
|
58
|
-
class Zones #:nodoc:
|
59
|
-
attr_reader :list
|
60
|
-
|
61
|
-
def initialize
|
62
|
-
@list = []
|
63
|
-
end
|
64
|
-
|
65
|
-
# Called by the index data to define a timezone for the country.
|
66
|
-
def timezone(identifier, latitude_numerator, latitude_denominator,
|
67
|
-
longitude_numerator, longitude_denominator, description = nil)
|
68
|
-
@list << CountryTimezone.new!(identifier, latitude_numerator,
|
69
|
-
latitude_denominator, longitude_numerator, longitude_denominator,
|
70
|
-
description)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,140 +0,0 @@
|
|
1
|
-
module TZInfo
|
2
|
-
# Use send as a workaround for erroneous 'wrong number of arguments' errors
|
3
|
-
# with JRuby 9.0.5.0 when calling methods with Java implementations. See #114.
|
4
|
-
send(:using, RubyCoreSupport::UntaintExt) if RubyCoreSupport.const_defined?(:UntaintExt)
|
5
|
-
|
6
|
-
# A DataSource that loads data from the set of Ruby modules included in the
|
7
|
-
# TZInfo::Data library (tzinfo-data gem).
|
8
|
-
#
|
9
|
-
# To have TZInfo use this DataSource, call TZInfo::DataSource.set as follows:
|
10
|
-
#
|
11
|
-
# TZInfo::DataSource.set(:ruby)
|
12
|
-
class RubyDataSource < DataSource
|
13
|
-
# Whether the timezone index has been loaded yet.
|
14
|
-
@@timezone_index_loaded = false
|
15
|
-
|
16
|
-
# Whether the country index has been loaded yet.
|
17
|
-
@@country_index_loaded = false
|
18
|
-
|
19
|
-
# Initializes a new RubyDataSource instance.
|
20
|
-
def initialize
|
21
|
-
tzinfo_data = File.join('tzinfo', 'data')
|
22
|
-
begin
|
23
|
-
require(tzinfo_data)
|
24
|
-
|
25
|
-
data_file = File.join('', 'tzinfo', 'data.rb')
|
26
|
-
path = $".reverse_each.detect {|p| p.end_with?(data_file) }
|
27
|
-
if path
|
28
|
-
@base_path = File.join(File.dirname(path), 'data').untaint
|
29
|
-
else
|
30
|
-
@base_path = tzinfo_data
|
31
|
-
end
|
32
|
-
rescue LoadError
|
33
|
-
@base_path = tzinfo_data
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Returns a TimezoneInfo instance for a given identifier.
|
38
|
-
# Raises InvalidTimezoneIdentifier if the timezone is not found or the
|
39
|
-
# identifier is invalid.
|
40
|
-
def load_timezone_info(identifier)
|
41
|
-
raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier !~ /\A[A-Za-z0-9+\-_]+(\/[A-Za-z0-9+\-_]+)*\z/
|
42
|
-
|
43
|
-
identifier = identifier.gsub(/-/, '__m__').gsub(/\+/, '__p__')
|
44
|
-
|
45
|
-
# Untaint identifier after it has been reassigned to a new string. We
|
46
|
-
# don't want to modify the original identifier. identifier may also be
|
47
|
-
# frozen and therefore cannot be untainted.
|
48
|
-
identifier.untaint
|
49
|
-
|
50
|
-
identifier = identifier.split('/')
|
51
|
-
begin
|
52
|
-
require_definition(identifier)
|
53
|
-
|
54
|
-
m = Data::Definitions
|
55
|
-
identifier.each {|part|
|
56
|
-
m = m.const_get(part)
|
57
|
-
}
|
58
|
-
|
59
|
-
m.get
|
60
|
-
rescue LoadError, NameError => e
|
61
|
-
raise InvalidTimezoneIdentifier, e.message
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Returns an array of all the available timezone identifiers.
|
66
|
-
def timezone_identifiers
|
67
|
-
load_timezone_index
|
68
|
-
Data::Indexes::Timezones.timezones
|
69
|
-
end
|
70
|
-
|
71
|
-
# Returns an array of all the available timezone identifiers for
|
72
|
-
# data timezones (i.e. those that actually contain definitions).
|
73
|
-
def data_timezone_identifiers
|
74
|
-
load_timezone_index
|
75
|
-
Data::Indexes::Timezones.data_timezones
|
76
|
-
end
|
77
|
-
|
78
|
-
# Returns an array of all the available timezone identifiers that
|
79
|
-
# are links to other timezones.
|
80
|
-
def linked_timezone_identifiers
|
81
|
-
load_timezone_index
|
82
|
-
Data::Indexes::Timezones.linked_timezones
|
83
|
-
end
|
84
|
-
|
85
|
-
# Returns a CountryInfo instance for the given ISO 3166-1 alpha-2
|
86
|
-
# country code. Raises InvalidCountryCode if the country could not be found
|
87
|
-
# or the code is invalid.
|
88
|
-
def load_country_info(code)
|
89
|
-
load_country_index
|
90
|
-
info = Data::Indexes::Countries.countries[code]
|
91
|
-
raise InvalidCountryCode, 'Invalid country code' unless info
|
92
|
-
info
|
93
|
-
end
|
94
|
-
|
95
|
-
# Returns an array of all the available ISO 3166-1 alpha-2
|
96
|
-
# country codes.
|
97
|
-
def country_codes
|
98
|
-
load_country_index
|
99
|
-
Data::Indexes::Countries.countries.keys.freeze
|
100
|
-
end
|
101
|
-
|
102
|
-
# Returns the name of this DataSource.
|
103
|
-
def to_s
|
104
|
-
"Ruby DataSource"
|
105
|
-
end
|
106
|
-
|
107
|
-
private
|
108
|
-
|
109
|
-
# Requires a zone definition by its identifier (split on /).
|
110
|
-
def require_definition(identifier)
|
111
|
-
require_data(*(['definitions'] + identifier))
|
112
|
-
end
|
113
|
-
|
114
|
-
# Requires an index by its name.
|
115
|
-
def require_index(name)
|
116
|
-
require_data(*['indexes', name])
|
117
|
-
end
|
118
|
-
|
119
|
-
# Requires a file from tzinfo/data.
|
120
|
-
def require_data(*file)
|
121
|
-
require(File.join(@base_path, *file))
|
122
|
-
end
|
123
|
-
|
124
|
-
# Loads in the index of timezones if it hasn't already been loaded.
|
125
|
-
def load_timezone_index
|
126
|
-
unless @@timezone_index_loaded
|
127
|
-
require_index('timezones')
|
128
|
-
@@timezone_index_loaded = true
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# Loads in the index of countries if it hasn't already been loaded.
|
133
|
-
def load_country_index
|
134
|
-
unless @@country_index_loaded
|
135
|
-
require_index('countries')
|
136
|
-
@@country_index_loaded = true
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|