Class: TZInfo::Data::TZDataFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/tzinfo/data/tzdataparser.rb

Overview

A tz data Zone format string. Either alternate standard/daylight-savings, substitution (%s) format or a fixed string.

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ TZDataFormat

:nodoc:



1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
# File 'lib/tzinfo/data/tzdataparser.rb', line 1171

def initialize(spec)
  if spec =~ /([A-z]+)\/([A-z]+)/
    @type = :alternate
    @standard_abbrev = $1
    @daylight_abbrev = $2
  elsif spec =~ /%s/
    @type = :subst
    @abbrev = spec
  else
    @type = :fixed
    @abbrev = spec
  end
end

Instance Method Details

#expand(std_offset, rule_string) ⇒ Object

Expands given the current daylight savings offset and Rule string.



1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
# File 'lib/tzinfo/data/tzdataparser.rb', line 1186

def expand(std_offset, rule_string)
  if @type == :alternate
    if std_offset == 0
      @standard_abbrev
    else
      @daylight_abbrev
    end
  elsif @type == :subst
    sprintf(@abbrev, rule_string)
  else
    @abbrev
  end        
end

#fixed?Boolean

Is a fixed format string.

Returns:

  • (Boolean)


1206
1207
1208
# File 'lib/tzinfo/data/tzdataparser.rb', line 1206

def fixed?
  @type == :fixed
end

#requires_rule_string?Boolean

True if a string from the rule is required to expand this format.

Returns:

  • (Boolean)


1201
1202
1203
# File 'lib/tzinfo/data/tzdataparser.rb', line 1201

def requires_rule_string?
  @type == :subst
end