Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit cb100ca02bf0652e39a61e7687a6ac034b1a9c43 1 parent 1509844
@stopdropandrew stopdropandrew authored
View
4 activesupport/CHANGELOG.md
@@ -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.
View
4 activesupport/lib/active_support/time_with_zone.rb
@@ -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
View
11 activesupport/test/core_ext/time_with_zone_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.