aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2013-11-02 15:40:16 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2013-11-02 15:40:16 -0700
commit423249504a2b468d7a273cbe6accf4f21cb0e643 (patch)
treeb8794f5ff4660ad7d0959bff9f9601af11cd50b0 /activesupport
parentdb41eb8a6ea88b854bf5cd11070ea4245e1639c5 (diff)
downloadrails-423249504a2b468d7a273cbe6accf4f21cb0e643.tar.gz
rails-423249504a2b468d7a273cbe6accf4f21cb0e643.tar.bz2
rails-423249504a2b468d7a273cbe6accf4f21cb0e643.zip
Added Numeric#in_milliseconds, like 1.hour.in_milliseconds, so we can feed them to JavaScript functions like getTime().
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md4
-rw-r--r--activesupport/lib/active_support/core_ext/numeric/time.rb6
-rw-r--r--activesupport/test/core_ext/numeric_ext_test.rb4
3 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 2d934f8bc4..e718e79877 100644
--- a/activesupport/CHANGELOG.md
+++ b/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*
diff --git a/activesupport/lib/active_support/core_ext/numeric/time.rb b/activesupport/lib/active_support/core_ext/numeric/time.rb
index 87b9a23aef..d97ce938c1 100644
--- a/activesupport/lib/active_support/core_ext/numeric/time.rb
+++ b/activesupport/lib/active_support/core_ext/numeric/time.rb
@@ -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
diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb
index 1da72eb17d..23bbb8d7d2 100644
--- a/activesupport/test/core_ext/numeric_ext_test.rb
+++ b/activesupport/test/core_ext/numeric_ext_test.rb
@@ -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