Class: TZInfo::TZDataFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/tzinfo/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:



1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
# File 'lib/tzinfo/tzdataparser.rb', line 1079

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.



1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
# File 'lib/tzinfo/tzdataparser.rb', line 1094

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)


1114
1115
1116
# File 'lib/tzinfo/tzdataparser.rb', line 1114

def fixed?
  @type == :fixed
end

#requires_rule_string?Boolean

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

Returns:

  • (Boolean)


1109
1110
1111
# File 'lib/tzinfo/tzdataparser.rb', line 1109

def requires_rule_string?
  @type == :subst
end