Permalink
Browse files

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.
  • Loading branch information...
pixeltrix committed Mar 28, 2017
1 parent ea0e18d commit ec9b4d39108d4c22d00426fa95c61b8b37dfe4e3
View
@@ -1,3 +1,12 @@
* 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.
*Andrew White*
* Fixed bug in `DateAndTime::Compatibility#to_time` that caused it to
raise `RuntimeError: can't modify frozen Time` when called on any frozen `Time`.
Properly pass through the frozen `Time` or `ActiveSupport::TimeWithZone` object
@@ -22,7 +31,7 @@
## Rails 5.0.2 (March 01, 2017) ##
* In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional
argument for `Marshal#load( source [, proc] )`. This way we don't have to do
argument for `Marshal#load( source [, proc] )`. This way we don't have to do
`Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc.
*Jeff Latz*
@@ -250,14 +250,21 @@ def us_zones
# 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
@@ -514,6 +514,10 @@ def test_country_zones
assert !ActiveSupport::TimeZone.country_zones(:ru).include?(ActiveSupport::TimeZone["Kuala Lumpur"])
end
def test_country_zones_without_mappings
assert_includes ActiveSupport::TimeZone.country_zones(:sv), ActiveSupport::TimeZone["America/El_Salvador"]
end
def test_to_yaml
assert_equal("--- !ruby/object:ActiveSupport::TimeZone\nname: Pacific/Honolulu\n", ActiveSupport::TimeZone["Hawaii"].to_yaml)
assert_equal("--- !ruby/object:ActiveSupport::TimeZone\nname: Europe/London\n", ActiveSupport::TimeZone["Europe/London"].to_yaml)

0 comments on commit ec9b4d3

Please sign in to comment.