Replace AS::TimeWithZone#since with alias to + #18063
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stems from Google group discussion.
Currently
AS::TimeWithZone
has two methods to add an interval to a time:+(other)
andsince(other)
(docs).The two methods are "pretty much" equivalent in every case:
When adding any interval to an
AS::TimeWithZone
representing aTime
:When adding any interval to an
AS::TimeWithZone
representing aDate
:When adding any interval to an
AS::TimeWithZone
representing aDateTime
:As you can see, the only case in which they differ is when the interval added to a
DateTime
is in a format like1.month
.However, this usage of "since" is explicitly discouraged by the documentation of
DateTime#since
:And indeed, following this recommendation the correct result is returned:
Therefore, my proposal is to remove the method definition of
TimeWithZone#since
and instead replace it with a simplealias_method :since, :+
.The rationale is that the only case where they differ is a case that is explicitly discouraged as "wrong".
In my opinion, having two methods named
since
and+
and having to figure out exactly what the difference is makes the codebase more confusing.However, I understand this PR is "subjective", so if you feel like it's better to ignore this, feel free to close the PR.
Thanks!