提交 7fb2a637 编写于 作者: A Andrew White

Add Time#sec_fraction

Mirrors the DateTime#sec_fraction method by returning the fraction
of the second as a Rational.
上级 f5dcc141
* Add `Time#sec_fraction` to return the fraction of a second as a `Rational`.
*Andrew White*
* Add `ActiveSupport.to_time_preserves_timezone` config option to control
how `to_time` handles timezones. In Ruby 2.4+ the behavior will change
from converting to the local system timezone to preserving the timezone
......
......@@ -73,6 +73,13 @@ def seconds_until_end_of_day
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册