Permalink
Browse files

TimeWithZone time conversions don't need to be wrapped in TimeOrDateT…

…ime, because TZInfo does this internally

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9106 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent e4645e0 commit 129d94477b1bb4478d1d8ceaed2a0f9a615e2d23 @gbuesing gbuesing committed Mar 28, 2008
View
@@ -1,5 +1,7 @@
*SVN*
+* TimeWithZone time conversions don't need to be wrapped in TimeOrDateTime, because TZInfo does this internally [Geoff Buesing]
+
* TimeWithZone#usec returns 0 instead of error when DateTime is wrapped [Geoff Buesing]
* Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria, Sunny Ripert]
@@ -12,12 +12,12 @@ def initialize(utc_time, time_zone, local_time = nil, period = nil)
# Returns a Time or DateTime instance that represents the time in time_zone
def time
- @time ||= utc_to_local
+ @time ||= period.to_local(@utc)
end
# Returns a Time or DateTime instance that represents the time in UTC
def utc
- @utc ||= local_to_utc
+ @utc ||= period.to_utc(@time)
end
alias_method :comparable_time, :utc
alias_method :getgm, :utc
@@ -240,15 +240,5 @@ def get_period_and_ensure_valid_local_time
def transfer_time_values_to_utc_constructor(time)
::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:usec) ? time.usec : 0)
end
-
- # Replicating logic from TZInfo::Timezone#utc_to_local because we want to cache the period in an instance variable for reuse
- def utc_to_local
- ::TZInfo::TimeOrDateTime.wrap(utc) {|utc| period.to_local(utc)}
- end
-
- # Replicating logic from TZInfo::Timezone#local_to_utc because we want to cache the period in an instance variable for reuse
- def local_to_utc
- ::TZInfo::TimeOrDateTime.wrap(time) {|time| period.to_utc(time)}
- end
end
end
@@ -372,6 +372,18 @@ def test_ruby_19_weekday_name_query_methods
assert_equal ruby_19_or_greater, @twz.respond_to?(name)
end
end
+
+ def test_utc_to_local_conversion_with_far_future_datetime
+ silence_warnings do # silence warnings raised by tzinfo gem
+ assert_equal [0,0,19,31,12,2049], ActiveSupport::TimeWithZone.new(DateTime.civil(2050), @time_zone).to_a[0,6]
+ end
+ end
+
+ def test_local_to_utc_conversion_with_far_future_datetime
+ silence_warnings do # silence warnings raised by tzinfo gem
+ assert_equal DateTime.civil(2050).to_f, ActiveSupport::TimeWithZone.new(nil, @time_zone, DateTime.civil(2049,12,31,19)).to_f
+ end
+ end
end
class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase

0 comments on commit 129d944

Please sign in to comment.