Skip to content

Commit

Permalink
Added Numeric#in_milliseconds, like 1.hour.in_milliseconds, so we can…
Browse files Browse the repository at this point in the history
… feed them to JavaScript functions like getTime().
  • Loading branch information
dhh committed Nov 2, 2013
1 parent db41eb8 commit 4232495
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions activesupport/CHANGELOG.md
@@ -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*
Expand Down
6 changes: 6 additions & 0 deletions activesupport/lib/active_support/core_ext/numeric/time.rb
Expand Up @@ -76,4 +76,10 @@ def since(time = ::Time.current)

# 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
4 changes: 4 additions & 0 deletions activesupport/test/core_ext/numeric_ext_test.rb
Expand Up @@ -440,4 +440,8 @@ def test_to_s__injected_on_proper_types
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

0 comments on commit 4232495

Please sign in to comment.