PostgreSQL interval datatype support?

How about to add support for interval datatype in rails? There is ActiveSupport:Duration class, that allows to use magic like 10.hours

I want to do something like:

create_table :events do |t|

t.string :name

t.interval :duration


Event.create(name: ‘Greatest event’, duration: 5.hours + 30.minutes)

Event.last.duration # => 19800

Event.last.duration.inspect # => “330 minutes and 0 seconds”

I’ve done some working (at first glance) initializer for Rails 4.1 here:

So, if Core Team agree I’ll be happy to make pull request for current master with this stuff (with tests and all input|output formats from documentation: ).

But I don’t sure about ActiveSupport::Duration. It’s weird and magic thing I’m afraid of.

I still want to do it.

There is some need to improve ActiveSupport::Duration (add ability to be created by parsing from ISO 8601 Duration and to be output to it), may be also fix some things. I’ve found awesome gem ISO8601 but it’s reimplement all types (date, times, durations). I can pick some required logic from it into ActiveSupport::Duration (or may be it’s better to use the whole gem in Rails?). Should these changes go into separate pull request or not?

Hey, sorry for the delay.

I’ll check with Yves and Matthew to see what they think about it but I’m positive for this addition.

Created #16917 and #16919 with this stuff (really want to include it in 4.2 if it is still possible). Thanks for your time!