Browse files

TimeZone#now returns an ActiveSupport::TimeWithZone

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8710 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent cb8de22 commit 213fac6f49532e7ee08348542e80465088b9bf5d @gbuesing gbuesing committed Jan 23, 2008
View
2 activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* TimeZone#now returns an ActiveSupport::TimeWithZone [Geoff Buesing]
+
* Time #in_current_time_zone and #change_time_zone_to_current return self when Time.zone is nil [Geoff Buesing]
* Remove unneeded #to_datetime_default_s alias for DateTime#to_s, given that we inherit a #to_default_s from Date that does exactly the same thing [Geoff Buesing]
View
17 activesupport/lib/active_support/values/time_zone.rb
@@ -177,22 +177,27 @@ def to_s
begin # the following methods depend on the tzinfo gem
require_library_or_gem "tzinfo" unless Object.const_defined?(:TZInfo)
- # Compute and return the current time, in the time zone represented by
- # +self+.
+ # Returns an ActiveSupport::TimeWithZone instance representing the current time
+ # in the time zone represented by +self+. Example:
+ #
+ # Time.zone = 'Hawaii' # => "Hawaii"
+ # Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00
def now
- tzinfo.now
+ tzinfo.now.change_time_zone(self)
end
# Return the current date in this time zone.
def today
- now.to_date
+ tzinfo.now.to_date
end
- # Adjust the given time to the time zone represented by +self+.
+ # Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a
+ # Time.utc() instance -- if you want an ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
def utc_to_local(time)
tzinfo.utc_to_local(time)
end
-
+
+ # Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance.
def local_to_utc(time, dst=true)
tzinfo.local_to_utc(time, dst)
end
View
5 activesupport/test/time_zone_test.rb
@@ -55,7 +55,10 @@ def test_period_for_local
uses_mocha 'TestTimeZoneNowAndToday' do
def test_now
TZInfo::DataTimezone.any_instance.stubs(:now).returns(Time.utc(2000))
- assert_equal Time.utc(2000), TimeZone['Eastern Time (US & Canada)'].now
+ zone = TimeZone['Eastern Time (US & Canada)']
+ assert_instance_of ActiveSupport::TimeWithZone, zone.now
+ assert_equal Time.utc(2000), zone.now.time
+ assert_equal zone, zone.now.time_zone
end
def test_today

0 comments on commit 213fac6

Please sign in to comment.