Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • T torque-postgresql
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 6
    • Issues 6
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Carlos
  • torque-postgresql
  • Wiki
  • Interval

Interval · Changes

Page history
How it works authored Apr 11, 2017 by Carlos's avatar Carlos
Show whitespace changes
Inline Side-by-side
Interval.md
View page @ 7b4860ff
Reads Postgresql's interval data type and transforms it into Rails' `ActiveSupport::Duration`. [PostgreSQL Docs](https://www.postgresql.org/docs/9.4/static/datatype-datetime.html#DATATYPE-INTERVAL-INPUT)
Reads PostgreSQL's interval data type and transforms it into Rails' `ActiveSupport::Duration`. [PostgreSQL Docs](https://www.postgresql.org/docs/9.4/static/datatype-datetime.html#DATATYPE-INTERVAL-INPUT)
# How it works
### Migration
Just set the type of the column as `interval` when creating a table.
```ruby
create_table "courses" do |t|
t.string "title", null: false
t.interval "duration"
end
```
Or when you are adding or column, just use `:interval` as type.
```ruby
add_column :courses, :duration, :interval
```
### Using it
The column is automatically identified and the value is turn into `ActiveSupport::Duration`. So any of the methods available on it can be used direct from your field. [RubyOnRails Doc](http://api.rubyonrails.org/classes/ActiveSupport/Duration.html)
```ruby
# Shows when you'll be finishing the course
course.duration.from_now
```
\ No newline at end of file
Clone repository
  • Arel
  • Auxiliary Statements
  • Belongs to Many
  • Box
  • Circle
  • Configuring
  • Date Time Range
  • Distinct On
  • Dynamic Attributes
  • Enum Set
  • Enum
  • Has Many
  • Home
  • Inherited Tables
  • Insert All
View All Pages