1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Added Numeric#in_milliseconds, like 1.hour.in_milliseconds, so we can feed them to JavaScript functions like getTime().

This commit is contained in:
David Heinemeier Hansson 2013-11-02 15:40:16 -07:00
parent db41eb8a6e
commit 423249504a
3 changed files with 14 additions and 0 deletions

View file

@ -1,3 +1,7 @@
* Added Numeric#in_milliseconds, like 1.hour.in_milliseconds, so we can feed them to JavaScript functions like getTime().
*DHH*
* Calling ActiveSupport::JSON.decode with unsupported options now raises an error.
*Godfrey Chan*

View file

@ -76,4 +76,10 @@ class Numeric
# Reads best without arguments: 10.minutes.from_now
alias :from_now :since
# Used with the standard time durations, like 1.hour.in_milliseconds --
# so we can feed them to JavaScript functions like getTime().
def in_milliseconds
self * 1000
end
end

View file

@ -440,4 +440,8 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
assert_equal BigDecimal, BigDecimal("1000010").class
assert_equal '1 Million', BigDecimal("1000010").to_s(:human)
end
def test_in_milliseconds
assert_equal 10_000, 10.seconds.in_milliseconds
end
end