Repository navigation
Change 1.week to create 1 week durations instead of 7 days durations. - #22806
Conversation
|
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
|
@pixeltrix, could you please review? |
|
Can anyone review? Is there anything stop this small PR from being merged? P.S> Now with signed commit! |
|
Nice, @Envek! What do Rails users need to know about compatibility? Does this affect current apps in any way? |
|
It should not affect current apps. Duration's So this is to remove astonishment from getting |
|
Sounds good! Would you please update the CHANGELOG message to cover this too? |
This is just to remove astonishment from getting `3600 seconds` from typing `1.hour`.
|
@jeremy, updated CHANGELOG, squashed and rebased. |
| It should not affect current apps as duration's `value` (number of seconds) remains the same, | ||
| only hash of `parts` (and `inspect` value) is changed and only when it's constructed by calling | ||
| methods on integers. Manual construction of Durations isn't affected. | ||
| Inside the ActiveSupport::Duration itself most operations rely only on number of seconds. |
There was a problem hiding this comment.
I think this line can be removed from CHANGELOG. It can be moved to commit message :)
There was a problem hiding this comment.
Infact the whole para can be moved to commit message.
There was a problem hiding this comment.
@prathamesh-sonpatki It's important for the changelog because it answers Rails users' primary question: will this break compatibility for my app / library / plugin?
Introduce weeks and hours periods to Duration. Change 1.week to create a 1 week duration instead of 7 days and 1.hour to create a 1 hour duration instead of 3600 seconds.
| if type == :seconds | ||
| t.since(sign * number) | ||
| elsif [:hours, :minutes].include?(type) | ||
| t.in_time_zone.advance(type => sign * number) |
There was a problem hiding this comment.
Regression:
>> Time.zone = 'Central Time (US & Canada)'
=> "Central Time (US & Canada)"
>> Time.now.utc
=> 2016-04-27 19:27:01 UTC
>> Time.now.utc + 1.second
=> 2016-04-27 19:27:05 UTC
>> Time.now.utc + 1.minute
=> Wed, 27 Apr 2016 14:28:36 CDT -05:00
>> Time.now.utc + 1.hour
=> Wed, 27 Apr 2016 15:27:39 CDT -05:00
>> Time.now.utc + 1.day
=> 2016-04-28 19:27:42 UTCWhy'd you do time zone conversion for hours & minutes only?
|
Reverting this pending regression consideration, fix, and test. |
|
Reverted @ c1ad19c |
|
@Envek it looks like you're using def sum(sign, time = ::Time.current) #:nodoc:
parts.inject(time) do |t,(type,number)|
if t.acts_like?(:time) || t.acts_like?(:date)
if type == :seconds
t.since(sign * number)
elsif type == :minutes
t.since(sign * number * 60)
elsif type == :hours
t.since(sign * number * 3600)
else
t.advance(type => sign * number)
end
else
raise ::ArgumentError, "expected a time or date, got #{time.inspect}"
end
end
endCan you submit a new PR - thanks! |
|
@jeremy, thank you for figuring out the regression. |
As it was proposed by @pixeltrix in discussion at #16917 (comment) I'm changing
ActiveSupport::Durationcreation with numeric methods like1.weekto create durations with more predictable and ISO8601-conformant parts. Because when1.houris actually3600 secondsit's logically correct, but not expected and confusing.See original discussion for details: #16917 (diff)
Before:
After:
r? @pixeltrix