aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb6
-rw-r--r--activesupport/test/time_zone_test.rb7
2 files changed, 13 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 5b2d42aa3c..788d40bfa8 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -201,6 +201,12 @@ module ActiveSupport
result
end
+ # Compare #name and TZInfo identifier to a supplied regexp, returning true
+ # if a match is found.
+ def =~(re)
+ return true if name =~ re || MAPPING[name] =~ re
+ end
+
# Returns a textual representation of this time zone.
def to_s
"(GMT#{formatted_offset}) #{name}"
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index b42dcd17f8..515ffcf0bf 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -250,6 +250,13 @@ class TimeZoneTest < Test::Unit::TestCase
assert zone1 == zone1
end
+ def test_zone_match
+ zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
+ assert zone =~ /Eastern/
+ assert zone =~ /New_York/
+ assert zone !~ /Nonexistent_Place/
+ end
+
def test_to_s
assert_equal "(GMT+03:00) Moscow", ActiveSupport::TimeZone['Moscow'].to_s
end