diff options
author | Rob Race <rob.race@me.com> | 2018-08-28 01:32:18 -0700 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-08-28 17:32:18 +0900 |
commit | 018ff582a5aaa58d4bce7d634ecae80d107f8304 (patch) | |
tree | 82f609f06fd893c9c3dc27a2cc57324747b1eed5 /activesupport/lib | |
parent | 37075aa7f5c2c779a981debd21aa8c468cce4d72 (diff) | |
download | rails-018ff582a5aaa58d4bce7d634ecae80d107f8304.tar.gz rails-018ff582a5aaa58d4bce7d634ecae80d107f8304.tar.bz2 rails-018ff582a5aaa58d4bce7d634ecae80d107f8304.zip |
Update the comments for TimeWithZone subtraction (#33721)
* Update the comments for TimeWithZone subtraction
While reading the description/documentation comments for the subtraction method, it was confusing. While in practical usage, the returned values make sense. It seems as though the explanation could be a bit clearer.
* Removed erroneous closing parenthesis
[ci skip]
[Rob Race + Ryuta Kamizono]
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 7e71318404..fb6956f64f 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -286,8 +286,10 @@ module ActiveSupport alias_method :since, :+ alias_method :in, :+ - # Returns a new TimeWithZone object that represents the difference between - # the current object's time and the +other+ time. + # Subtracts an interval of time and returns a new TimeWithZone object unless + # the other value `acts_like?` time. Then it will return a Float of the difference + # between the two times that represents the difference between the current + # object's time and the +other+ time. # # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)' # now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28 EST -05:00 @@ -302,6 +304,12 @@ module ActiveSupport # # now - 24.hours # => Sun, 02 Nov 2014 01:26:28 EDT -04:00 # now - 1.day # => Sun, 02 Nov 2014 00:26:28 EDT -04:00 + # + # If both the TimeWithZone object and the other value act like Time, a Float + # will be returned. + # + # Time.zone.now - 1.day.ago # => 86399.999967 + # def -(other) if other.acts_like?(:time) to_time - other.to_time |