diff options
author | Andrew White <andrew.white@unboxedconsulting.com> | 2016-04-23 17:15:26 +0100 |
---|---|---|
committer | Andrew White <andrew.white@unboxedconsulting.com> | 2016-04-23 17:15:26 +0100 |
commit | 7fb2a637086ae5e4cb8d06582ed7d9b29a6a4f58 (patch) | |
tree | b7cd114b5bce9c6b80bb7393a198dc05c770f6f7 /activesupport/lib/active_support | |
parent | f5dcc141ec19ae585326f5b424b81c0217a386c0 (diff) | |
download | rails-7fb2a637086ae5e4cb8d06582ed7d9b29a6a4f58.tar.gz rails-7fb2a637086ae5e4cb8d06582ed7d9b29a6a4f58.tar.bz2 rails-7fb2a637086ae5e4cb8d06582ed7d9b29a6a4f58.zip |
Add Time#sec_fraction
Mirrors the DateTime#sec_fraction method by returning the fraction
of the second as a Rational.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 768c9a1b2c..9c019e10b5 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -73,6 +73,13 @@ class Time end_of_day.to_i - to_i end + # Returns the fraction of a second as a +Rational+ + # + # Time.new(2012, 8, 29, 0, 0, 0.5).sec_fraction # => (1/2) + def sec_fraction + Rational(nsec, 1000000000) + end + # Returns a new Time where one or more of the elements have been changed according # to the +options+ parameter. The time options (<tt>:hour</tt>, <tt>:min</tt>, # <tt>:sec</tt>, <tt>:usec</tt>, <tt>:nsec</tt>) reset cascadingly, so if only |