Class SDL4R::RelativeTimezone

  1. lib/sdl4r/relative_timezone.rb
Parent: TZInfo::Timezone

Represents a Timezone which is distant from a standard timezone by a fixed offset.

Methods

public class

  1. get
  2. get_proxy
  3. new

public instance

  1. period_for_utc
  2. periods_for_local

Attributes

identifier [R]
relative_offset [R]

Public class methods

get (identifier)

Returns a timezone by its identifier (e.g. “Europe/London“, “America/Chicago“ or “UTC”).

Supports relative timezones in the following formats: “UTC+2”, “GMT+01:30”, “Europe/Paris-10:00”.

Raises InvalidTimezoneIdentifier if the timezone couldn’t be found.

[show source]
    # File lib/sdl4r/relative_timezone.rb, line 38
38:     def self.get(identifier)
39:       base_identifier, offset_text, offset = RelativeTimezone::parse_relative_identifier(identifier)
40: 
41:       tz = TZAbbreviationDB.get_timezone(base_identifier)
42: 
43:       offset ?
44:         RelativeTimezone.new(base_identifier + offset_text.to_s, offset_text, offset, tz) :
45:         tz
46:     end
get_proxy (identifier)

Returns a proxy for the Timezone with the given identifier. The proxy will cause the real timezone to be loaded when an attempt is made to find a period or convert a time. get_proxy will not validate the identifier. If an invalid identifier is specified, no exception will be raised until the proxy is used.

Supports relative timezones in the following format: “GMT+01:30”, “CET-10:00”.

[show source]
    # File lib/sdl4r/relative_timezone.rb, line 56
56:     def self.get_proxy(identifier)
57:       base_identifier, offset_text, offset = RelativeTimezone::parse_relative_identifier(identifier)
58: 
59:       proxy = TZAbbreviationDB.get_timezone_proxy(base_identifier)
60: 
61:       offset ?
62:         RelativeTimezone.new(base_identifier + offset_text.to_s, offset_text, offset, proxy) :
63:         proxy
64:     end
new (identifier, offset_text, offset, base_timezone)
[show source]
     # File lib/sdl4r/relative_timezone.rb, line 103
103:     def self.new(identifier, offset_text, offset, base_timezone)
104:       o = super()
105:       o.send(:_initialize, identifier, offset_text, offset, base_timezone)
106:       o
107:     end

Public instance methods

period_for_utc (utc)
[show source]
     # File lib/sdl4r/relative_timezone.rb, line 127
127:     def period_for_utc(utc)
128:       period = @base_timezone.period_for_utc(utc)
129: 
130:       translated_offset =
131:         period.offset ?
132:           TZInfo::TimezoneOffsetInfo.new(
133:             period.offset.utc_offset + @relative_offset,
134:             period.offset.std_offset,
135:             (period.offset.abbreviation.to_s + @relative_offset_text).to_sym) :
136:           nil
137: 
138:       return TZInfo::TimezonePeriod.new(nil, nil, translated_offset)
139:     end
periods_for_local (local)
[show source]
     # File lib/sdl4r/relative_timezone.rb, line 141
141:     def periods_for_local(local)
142:       periods = @base_timezone.periods_for_local(local)
143: 
144:       return periods.collect { |period|
145:         translated_offset =
146:           period.offset ?
147:             TZInfo::TimezoneOffsetInfo.new(
148:               period.offset.utc_offset + @relative_offset,
149:               period.offset.std_offset,
150:               (period.offset.abbreviation.to_s + @relative_offset_text).to_sym) :
151:             nil
152:         TZInfo::TimezonePeriod.new(nil, nil, translated_offset)
153:       }
154:     end