rails/rails — pull request #16917 by Envek (2014-09-14 13:54:05+00:00)
Title: Methods for ActiveSupport::Duration parsing from ISO 8601 and output to it

This PR add methods to `ActiveSupport::Duration` to allow present it in [ISO 8601 Duration] format and instantiate from it.

[ISO 8601 Duration] format is standartized way to represent duration for interchange, it's already recognized by some database engines (e.g. PostgreSQL) and client side libraries (e.g. [plugin for Moment.js durations](https://github.com/dordille/moment-isoduration)). So, I think it should be part of `ActiveSupport::Duration`.

Some parts of code and tests are taken from [ISO8601 gem] by Arnau Siches (@arnau) and contributors. Many thanks to them.

This PR is required for PostgreSQL `interval` datatype support (for converting it from and to `ActiveSupport::Duration`) as I've proposed in Google Group [here](https://groups.google.com/forum/#!topic/rubyonrails-core/zcscu1p4ucA). I will start write code for this PR right now. Because of that my parsing allows individual datetime parts to be negative (see [PostgreSQL interval output]).

There is no backward incompatible changes as I want it to be included in upcoming 4.2 release, if it still possible (pleeeaasee!).

[ISO 8601 Duration]: http://en.wikipedia.org/wiki/ISO_8601#Durations
[ISO8601 gem]: https://github.com/arnau/ISO8601
[PostgreSQL interval output]: http://www.postgresql.org/docs/9.4/static/datatype-datetime.html#DATATYPE-INTERVAL-OUTPUT