Class: TwitterCldr::Timezones::Timezone
- Inherits:
-
Object
- Object
- TwitterCldr::Timezones::Timezone
- Includes:
- Singleton
- Defined in:
- lib/twitter_cldr/timezones/timezone.rb
Constant Summary collapse
- ALL_FORMATS =
( GenericLocation::FORMATS + GmtLocation::FORMATS + Iso8601Location::FORMATS + [:zone_id, :zone_id_short] ).freeze
- GENERIC_TO_GMT_MAP =
{ generic_location: :long_gmt, generic_short: :short_gmt, generic_long: :long_gmt, specific_short: :short_gmt, specific_long: :long_gmt }.freeze
- UNKNOWN =
'unk'.freeze
Instance Attribute Summary collapse
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#orig_tz ⇒ Object
readonly
Returns the value of attribute orig_tz.
-
#tz ⇒ Object
readonly
Returns the value of attribute tz.
Class Method Summary collapse
Instance Method Summary collapse
- #display_name_for(date, format = :generic_location, dst = TZInfo::Timezone.default_dst, &block) ⇒ Object
- #generic_location ⇒ Object
- #gmt_location ⇒ Object
- #identifier ⇒ Object
-
#initialize(tz_id, locale) ⇒ Timezone
constructor
A new instance of Timezone.
- #iso_location ⇒ Object
- #max_locale ⇒ Object
- #orig_locale ⇒ Object
- #period_for_local(*args, &block) ⇒ Object
- #period_for_utc(time) ⇒ Object
- #transitions_up_to(date) ⇒ Object
Constructor Details
Instance Attribute Details
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
42 43 44 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 42 def locale @locale end |
#orig_tz ⇒ Object (readonly)
Returns the value of attribute orig_tz.
42 43 44 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 42 def orig_tz @orig_tz end |
#tz ⇒ Object (readonly)
Returns the value of attribute tz.
42 43 44 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 42 def tz @tz end |
Class Method Details
.instance(tz_id, locale = TwitterCldr.locale) ⇒ Object
31 32 33 |
# 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 |
Instance Method Details
#display_name_for(date, format = :generic_location, dst = TZInfo::Timezone.default_dst, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 50 def display_name_for(date, format = :generic_location, dst = TZInfo::Timezone.default_dst, &block) case format when *GenericLocation::FORMATS generic_location.display_name_for(date, format, dst, &block) || gmt_location.display_name_for(date, GENERIC_TO_GMT_MAP[format], dst, &block) when *GmtLocation::FORMATS gmt_location.display_name_for(date, format, dst, &block) when *Iso8601Location::FORMATS iso_location.display_name_for(date, format, dst, &block) 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 ⇒ Object
98 99 100 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 98 def generic_location @generic_location ||= GenericLocation.new(self) end |
#gmt_location ⇒ Object
102 103 104 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 102 def gmt_location @gmt_location ||= GmtLocation.new(self) end |
#identifier ⇒ Object
74 75 76 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 74 def identifier tz.identifier end |
#iso_location ⇒ Object
106 107 108 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 106 def iso_location @iso_location ||= Iso8601Location.new(self) end |
#max_locale ⇒ Object
94 95 96 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 94 def max_locale @max_locale ||= orig_locale.maximize end |
#orig_locale ⇒ Object
90 91 92 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 90 def orig_locale @orig_locale ||= TwitterCldr::Shared::Locale.new(locale) end |
#period_for_local(*args, &block) ⇒ Object
78 79 80 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 78 def period_for_local(*args, &block) tz.period_for_local(*args, &block) end |
#period_for_utc(time) ⇒ Object
82 83 84 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 82 def period_for_utc(time) tz.period_for_utc(time) end |
#transitions_up_to(date) ⇒ Object
86 87 88 |
# File 'lib/twitter_cldr/timezones/timezone.rb', line 86 def transitions_up_to(date) tz.transitions_up_to(date) end |