aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-01-25 18:23:22 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-01-25 18:23:22 +0000
commit4b2ac708b7666510d522fc706936d3c2ea5cbb80 (patch)
treed288b810dfd797f7c22d5c5964f3804aa78b517e /activesupport/lib
parenta7adca3d3b53df69cf45756f0459e501ee44d469 (diff)
downloadrails-4b2ac708b7666510d522fc706936d3c2ea5cbb80.tar.gz
rails-4b2ac708b7666510d522fc706936d3c2ea5cbb80.tar.bz2
rails-4b2ac708b7666510d522fc706936d3c2ea5cbb80.zip
Adding UTC zone to TimeZone; TimeWithZone no longer has to fake UTC zone with nil
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8720 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb15
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb3
2 files changed, 9 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 648fa16f4e..e65c77a8b6 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -5,7 +5,7 @@ module ActiveSupport
include Comparable
attr_reader :time_zone
- def initialize(utc_time, time_zone = nil, local_time = nil)
+ def initialize(utc_time, time_zone, local_time = nil)
@utc = utc_time
@time = local_time
@time_zone = time_zone
@@ -13,12 +13,12 @@ module ActiveSupport
# Returns a Time instance that represents the time in time_zone
def time
- @time ||= utc? ? @utc : time_zone.utc_to_local(@utc)
+ @time ||= time_zone.utc_to_local(@utc)
end
# Returns a Time instance that represents the time in UTC
def utc
- @utc ||= utc? ? @time : time_zone.local_to_utc(@time)
+ @utc ||= time_zone.local_to_utc(@time)
end
alias_method :comparable_time, :utc
@@ -53,16 +53,15 @@ module ActiveSupport
end
def dst?
- utc? ? false : period.dst?
+ period.dst?
end
- # The TimeZone class has no zone for UTC, so this class uses the absence of a time zone to indicate UTC
def utc?
- !time_zone
+ time_zone.name == 'UTC'
end
def utc_offset
- utc? ? 0 : period.utc_total_offset
+ period.utc_total_offset
end
def formatted_offset(colon = true, alternate_utc_string = nil)
@@ -71,7 +70,7 @@ module ActiveSupport
# Time uses #zone to display the time zone abbreviation, so we're duck-typing it
def zone
- utc? ? 'UTC' : period.abbreviation.to_s
+ period.abbreviation.to_s
end
def inspect
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 259b49a50a..d277130c00 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -40,6 +40,7 @@ class TimeZone
"London" => "Europe/London",
"Casablanca" => "Africa/Casablanca",
"Monrovia" => "Africa/Monrovia",
+ "UTC" => "UTC",
"Belgrade" => "Europe/Belgrade",
"Bratislava" => "Europe/Bratislava",
"Budapest" => "Europe/Budapest",
@@ -259,7 +260,7 @@ class TimeZone
[ -7_200, "Mid-Atlantic" ],
[ -3_600, "Azores", "Cape Verde Is." ],
[ 0, "Dublin", "Edinburgh", "Lisbon", "London", "Casablanca",
- "Monrovia" ],
+ "Monrovia", "UTC" ],
[ 3_600, "Belgrade", "Bratislava", "Budapest", "Ljubljana", "Prague",
"Sarajevo", "Skopje", "Warsaw", "Zagreb", "Brussels",
"Copenhagen", "Madrid", "Paris", "Amsterdam", "Berlin",