class TZInfo::DataSources::PosixTimeZoneParser
def parse(tz_string)
-
(InvalidPosixTimeZone)
- if `tz_string` is is not valid. -
(InvalidPosixTimeZone)
- if `tz_string` is not a `String`.
Returns:
-
(Object)
- either a {TimezoneOffset} for a constantly applied
Parameters:
-
tz_string
(String
) -- the string to parse.
def parse(tz_string) raise InvalidPosixTimeZone unless tz_string.kind_of?(String) return nil if tz_string.empty? s = StringScanner.new(tz_string) check_scan(s, /([^-+,\d<][^-+,\d]*) | <([^>]+)>/x) std_abbrev = @string_deduper.dedupe(RubyCoreSupport.untaint(s[1] || s[2])) check_scan(s, /([-+]?\d+)(?::(\d+)(?::(\d+))?)?/) std_offset = get_offset_from_hms(s[1], s[2], s[3]) if s.scan(/([^-+,\d<][^-+,\d]*) | <([^>]+)>/x) dst_abbrev = @string_deduper.dedupe(RubyCoreSupport.untaint(s[1] || s[2])) if s.scan(/([-+]?\d+)(?::(\d+)(?::(\d+))?)?/) dst_offset = get_offset_from_hms(s[1], s[2], s[3]) else # POSIX is negative for ahead of UTC. dst_offset = std_offset - 3600 end dst_difference = std_offset - dst_offset start_rule = parse_rule(s, 'start') end_rule = parse_rule(s, 'end') raise InvalidPosixTimeZone, "Expected the end of a POSIX-style time zone string but found '#{s.rest}'." if s.rest? if start_rule.is_always_first_day_of_year? && start_rule.transition_at == 0 && end_rule.is_always_last_day_of_year? && end_rule.transition_at == 86400 + dst_difference # Constant daylight savings time. # POSIX is negative for ahead of UTC. TimezoneOffset.new(-std_offset, dst_difference, dst_abbrev) else AnnualRules.new( TimezoneOffset.new(-std_offset, 0, std_abbrev), TimezoneOffset.new(-std_offset, dst_difference, dst_abbrev), start_rule, end_rule) end elsif !s.rest? # Constant standard time. # POSIX is negative for ahead of UTC. TimezoneOffset.new(-std_offset, 0, std_abbrev) else raise InvalidPosixTimeZone, "Expected the end of a POSIX-style time zone string but found '#{s.rest}'." end end