You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ActiveSupport::Duration::ISO8601Parser::ParsingError: InvalidISO8601duration: "P1W4DT13H46M40S"mixingweekswithotherdateparts not allowed
System configuration
Rails 5.2.1
Ruby 2.3.1
There's an Exception prohibiting mixing weeks with other date pieces. Although it seems a correct Exception, it makes the process confusing since I could measure a duration by "2 months and 1 week" in any other aspect, and it would also provide a correct behavior on ActiveSupport::Duration#parse
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 5-2-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.
I can confirm this bug is still present in Rails 5.2.3 / Ruby 2.6.3
Checking the ISO8601, mixing of week with other date parts is not allowed. Therefore I would suggest to change the ActiveSupport::Duration::ISO8601Serializer to:
def serialize
parts, sign = normalize
return "PT0S" if parts.empty?
if parts.key?(:weeks) && parts.except(:weeks).present?
parts[:days] = (parts[:days] || 0) + 7 * parts[:weeks]
parts.delete(:weeks)
end
output = +"P"
output << "#{parts[:years]}Y" if parts.key?(:years)
output << "#{parts[:months]}M" if parts.key?(:months)
output << "#{parts[:weeks]}W" if parts.key?(:weeks)
output << "#{parts[:days]}D" if parts.key?(:days)
time = +""
time << "#{parts[:hours]}H" if parts.key?(:hours)
time << "#{parts[:minutes]}M" if parts.key?(:minutes)
if parts.key?(:seconds)
time << "#{sprintf(@precision ? "%0.0#{@precision}f" : '%g', parts[:seconds])}S"
end
output << "T#{time}" unless time.empty?
"#{sign}#{output}"
end
There was a pull request: #34683, to solve this issue but it never got merged.
Steps to reproduce
Expected behavior
Actual behavior
System configuration
Rails 5.2.1
Ruby 2.3.1
There's an Exception prohibiting mixing weeks with other date pieces. Although it seems a correct Exception, it makes the process confusing since I could measure a duration by "2 months and 1 week" in any other aspect, and it would also provide a correct behavior on
ActiveSupport::Duration#parse
The solutions simply remove the exception and allow it to move forward.
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/duration/iso8601_parser.rb#L106
The text was updated successfully, but these errors were encountered: