aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2008-01-29 01:09:49 +0000
committerRick Olson <technoweenie@gmail.com>2008-01-29 01:09:49 +0000
commitbd72d06374600cb20bbc85127ab8629dd1b2453c (patch)
tree6bfc7c9da6c53c5288d36aaa6b03dd421116d1e0 /activesupport
parent859ca3a1ea23684c02c39de057e1810b05bd6a46 (diff)
downloadrails-bd72d06374600cb20bbc85127ab8629dd1b2453c.tar.gz
rails-bd72d06374600cb20bbc85127ab8629dd1b2453c.tar.bz2
rails-bd72d06374600cb20bbc85127ab8629dd1b2453c.zip
Support retrieving TimeZones with a Duration. TimeZone[-28800] == TimeZone[-480.minutes]. [rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8746 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb5
-rw-r--r--activesupport/test/time_zone_test.rb8
3 files changed, 13 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 51e073b1bd..8fb730dfd8 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Support retrieving TimeZones with a Duration. TimeZone[-28800] == TimeZone[-480.minutes]. [rick]
+
* TimeWithZone#- added, so that #- can handle a Time or TimeWithZone argument correctly [Geoff Buesing]
* with_timezone test helper renamed with_env_tz, to distinguish between setting ENV['TZ'] and setting Time.zone in tests [Geoff Buesing]
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index d277130c00..fce352d3ad 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -6,6 +6,7 @@ class TimeZone
"Hawaii" => "Pacific/Honolulu",
"Alaska" => "America/Juneau",
"Pacific Time (US & Canada)" => "America/Los_Angeles",
+ 'PST' => "America/Los_Angeles",
"Tijuana" => "America/Tijuana",
"Mountain Time (US & Canada)" => "America/Denver",
"Arizona" => "America/Phoenix",
@@ -247,7 +248,7 @@ class TimeZone
[[-39_600, "International Date Line West", "Midway Island", "Samoa" ],
[-36_000, "Hawaii" ],
[-32_400, "Alaska" ],
- [-28_800, "Pacific Time (US & Canada)", "Tijuana" ],
+ [-28_800, "Pacific Time (US & Canada)", 'PST', "Tijuana" ],
[-25_200, "Mountain Time (US & Canada)", "Chihuahua", "Mazatlan",
"Arizona" ],
[-21_600, "Central Time (US & Canada)", "Saskatchewan", "Guadalajara",
@@ -314,7 +315,7 @@ class TimeZone
when String
all # force the zones to be loaded
@@zones_map[arg]
- when Numeric
+ when Numeric, ActiveSupport::Duration
arg *= 3600 if arg.abs <= 13
all.find { |z| z.utc_offset == arg.to_i }
else
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index 23d9e3f4be..c32218cee2 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -36,6 +36,14 @@ class TimeZoneTest < Test::Unit::TestCase
end
end
+ def test_from_integer_to_map
+ assert_instance_of TimeZone, TimeZone[-28800] # PST
+ end
+
+ def test_from_duration_to_map
+ assert_instance_of TimeZone, TimeZone[-480.minutes] # PST
+ end
+
TimeZone.all.each do |zone|
name = zone.name.downcase.gsub(/[^a-z]/, '_')
define_method("test_from_#{name}_to_map") do