class TwitterCldr::Timezones::Timezone

Constants

ALL_FORMATS
GENERIC_TO_GMT_MAP
UNKNOWN

Attributes

locale[R]
orig_tz[R]
tz[R]

Public Class Methods

instance(tz_id, locale = TwitterCldr.locale) click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 31
def instance(tz_id, locale = TwitterCldr.locale)
  cache["#{tz_id}:#{locale}"] ||= new(tz_id, locale)
end
new(tz_id, locale) click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 44
def initialize(tz_id, locale)
  @orig_tz = TZInfo::Timezone.get(tz_id)
  @tz = TZInfo::Timezone.get(ZoneMeta.normalize(tz_id))
  @locale = locale
end

Private Class Methods

cache() click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 37
def cache
  @cache ||= {}
end

Public Instance Methods

display_name_for(date, format = :generic_location) click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 50
def display_name_for(date, format = :generic_location)
  case format
    when *GenericLocation::FORMATS
      generic_location.display_name_for(date, format) ||
        gmt_location.display_name_for(date, GENERIC_TO_GMT_MAP[format])

    when *GmtLocation::FORMATS
      gmt_location.display_name_for(date, format)

    when *Iso8601Location::FORMATS
      iso_location.display_name_for(date, format)

    when :zone_id
      identifier

    when :zone_id_short
      ZoneMeta.short_name_for(identifier) || UNKNOWN

    else
      raise ArgumentError, "'#{format}' is not a valid timezone format, "\
        "must be one of #{ALL_FORMATS.join(', ')}"
  end
end
generic_location() click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 94
def generic_location
  @generic_location ||= GenericLocation.new(self)
end
gmt_location() click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 98
def gmt_location
  @gmt_location ||= GmtLocation.new(self)
end
identifier() click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 74
def identifier
  tz.identifier
end
iso_location() click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 102
def iso_location
  @iso_location ||= Iso8601Location.new(self)
end
max_locale() click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 90
def max_locale
  @max_locale ||= orig_locale.maximize
end
orig_locale() click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 86
def orig_locale
  @orig_locale ||= TwitterCldr::Shared::Locale.new(locale)
end
period_for_local(date) click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 78
def period_for_local(date)
  tz.period_for_local(date)
end
transitions_up_to(date) click to toggle source
# File lib/twitter_cldr/timezones/timezone.rb, line 82
def transitions_up_to(date)
  tz.transitions_up_to(date)
end