diff options
author | Andrew White <andrew.white@unboxedconsulting.com> | 2016-04-23 19:18:38 +0100 |
---|---|---|
committer | Andrew White <andrew.white@unboxedconsulting.com> | 2016-04-23 19:18:38 +0100 |
commit | a424bbb2423297cc8bd80fc8b36f7169c3986a71 (patch) | |
tree | 6859ba8648f5f5e182dd54a5d0a9e78808208a29 /activesupport/lib/active_support/core_ext/date_time/calculations.rb | |
parent | 88d844b278163f19e910fc1acadf1dbb4afac527 (diff) | |
download | rails-a424bbb2423297cc8bd80fc8b36f7169c3986a71.tar.gz rails-a424bbb2423297cc8bd80fc8b36f7169c3986a71.tar.bz2 rails-a424bbb2423297cc8bd80fc8b36f7169c3986a71.zip |
Add DateTime#subsec
Mirrors the Time#subsec method by returning the fraction
of the second as a Rational.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date_time/calculations.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/calculations.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index 1eaf51243c..7e214524df 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -28,6 +28,13 @@ class DateTime end_of_day.to_i - to_i end + # Returns the fraction of a second as a +Rational+ + # + # DateTime.new(2012, 8, 29, 0, 0, 0.5).subsec # => (1/2) + def subsec + sec_fraction + end + # Returns a new DateTime 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>) reset cascadingly, so if only the hour is |