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:



1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
# File 'lib/tzinfo/tzdataparser.rb', line 1072

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.



1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
# File 'lib/tzinfo/tzdataparser.rb', line 1087

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)


1107
1108
1109
# File 'lib/tzinfo/tzdataparser.rb', line 1107

def fixed?
  @type == :fixed
end

#requires_rule_string?Boolean

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

Returns:

  • (Boolean)


1102
1103
1104
# File 'lib/tzinfo/tzdataparser.rb', line 1102

def requires_rule_string?
  @type == :subst
end