Permalink
Browse files

Merge pull request #9403 from stopdropandrew/TimeWithZone#to_r

Added `ActiveSupport::TimeWithZone#to_r` for `Time#at` compatibility.

Closes #9404
  • Loading branch information...
2 parents 70ec7e0 + cb100ca commit a06623609ee37f24b1b741098db52612b6f539ab @rafaelfranca rafaelfranca committed Feb 24, 2013
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* Added `ActiveSupport::TimeWithZone#to_r` for `Time#at` compatibility.
+
+ *stopdropandrew*
+
* `ActiveSupport::NumberHelper#number_to_human` returns the number unaltered when
the given units hash does not contain the needed key, e.g. when the number provided
is less than the largest key provided.
@@ -317,6 +317,10 @@ def to_i
end
alias_method :tv_sec, :to_i
+ def to_r
+ utc.to_r
+ end
+
# Return an instance of Time in the system timezone.
def to_time
utc.to_time
@@ -326,6 +326,17 @@ def test_to_i_with_wrapped_datetime
assert_equal 946684800, twz.to_i
end
+ def test_to_r
+ result = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1), ActiveSupport::TimeZone['Hawaii']).to_r
+ assert_equal Rational(946684800, 1), result
+ assert_kind_of Rational, result
+ end
+
+ def test_time_at
+ time = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1), ActiveSupport::TimeZone['Hawaii'])
+ assert_equal time, Time.at(time)
+ end
+
def test_to_time
with_env_tz 'US/Eastern' do
assert_equal Time, @twz.to_time.class

0 comments on commit a066236

Please sign in to comment.