class TZInfo::TZDataFormat
:nodoc:
@private
substitution (%s) format or a fixed string.
A tz data Zone format string. Either alternate standard/daylight-savings,
def expand(utc_offset, std_offset, rule_string)
Expands given the base offset to UTC, the current daylight savings
def expand(utc_offset, std_offset, rule_string) if @type == :alternate if std_offset == 0 @standard_abbrev else @daylight_abbrev end elsif @type == :subst @abbrev.gsub(/%([sz])/) do $1 == 's' ? rule_string : format_offset(utc_offset + std_offset) end else @abbrev end end
def fixed?
def fixed? @type == :fixed end
def format_offset(offset)
def format_offset(offset) if offset < 0 offset = -offset sign = '-' else sign = '+' end offset, seconds = offset.divmod(60) offset, minutes = offset.divmod(60) if offset > 99 # unsupported '%z' else result = "#{sign}#{offset.to_s.rjust(2, '0')}" if minutes != 0 || seconds != 0 result << minutes.to_s.rjust(2, '0') if seconds != 0 result << seconds.to_s.rjust(2, '0') end end result end end
def initialize(spec)
- Private: -
def initialize(spec) if spec =~ /\A([^\/]*)\/(.*)\z/ @type = :alternate @standard_abbrev = $1 @daylight_abbrev = $2 elsif spec =~ /%[sz]/ @type = :subst @abbrev = spec else @type = :fixed @abbrev = spec end end
def subst?
def subst? @type == :subst end