1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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]
This commit is contained in:
Rob Race 2018-08-28 01:32:18 -07:00 committed by Ryuta Kamizono
parent 37075aa7f5
commit 018ff582a5

View file

@ -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