diff options
author | Andrew White <andrew.white@unboxed.co> | 2017-03-28 13:11:55 +0100 |
---|---|---|
committer | Andrew White <andrew.white@unboxed.co> | 2017-03-28 13:33:32 +0100 |
commit | d28c48243521a978ba8d432092e11a4aafb2b154 (patch) | |
tree | 64698eb1d21b1d1673af721ae996d693735fd553 /activesupport/lib/active_support | |
parent | 5561412ac2a22c24e9c481821a99ddc9f55911a2 (diff) | |
download | rails-d28c48243521a978ba8d432092e11a4aafb2b154.tar.gz rails-d28c48243521a978ba8d432092e11a4aafb2b154.tar.bz2 rails-d28c48243521a978ba8d432092e11a4aafb2b154.zip |
Return unmapped timezones from `country_zones`
If a country doesn't exist in the MAPPINGS hash then create a new
`ActiveSupport::Timezone` instance using the supplied timezone id.
Fixes #28431.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 18477b9f6b..ce5207546d 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -250,14 +250,21 @@ module ActiveSupport # for time zones in the country specified by its ISO 3166-1 Alpha2 code. def country_zones(country_code) code = country_code.to_s.upcase - @country_zones[code] ||= - TZInfo::Country.get(code).zone_identifiers.map do |tz_id| - name = MAPPING.key(tz_id) - name && self[name] - end.compact.sort! + @country_zones[code] ||= load_country_zones(code) end private + def load_country_zones(code) + country = TZInfo::Country.get(code) + country.zone_identifiers.map do |tz_id| + if MAPPING.value?(tz_id) + self[MAPPING.key(tz_id)] + else + create(tz_id, nil, TZInfo::Timezone.new(tz_id)) + end + end.sort! + end + def zones_map @zones_map ||= begin MAPPING.each_key { |place| self[place] } # load all the zones |