Permalink
Browse files

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

  • Loading branch information...
stopdropandrew committed Feb 24, 2013
1 parent 1509844 commit cb100ca02bf0652e39a61e7687a6ac034b1a9c43
@@ -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 cb100ca

Please sign in to comment.