Sha256: 71fcb6eef65aaa9b0273e55519965293127eb2867c3eff238aa96277bcfa6025
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
# Groupdate The simplest way to group by: - day - week - month - hour - *and more* (complete list at bottom) :tada: Time zones supported!! PostgreSQL only at the moment - support for other datastores coming soon ## Usage ```ruby User.group_by_day(:created_at).count # => {"2013-04-16 00:00:00+00" => 50, "2013-04-17 00:00:00+00" => 100} Task.group_by_month(:updated_at).count # => {"2013-03-01 00:00:00+00" => 23, "2013-04-01 00:00:00+00" => 44} Goal.group_by_year(:accomplished_at).count # => {"2012-01-01 00:00:00+00" => 11, "2013-01-01 00:00:00+00" => 3} ``` The default time zone is `Time.zone`. Pass a time zone as the second argument. ```ruby time_zone = ActiveSupport::TimeZone["Pacific Time (US & Canada)"] User.group_by_week(:created_at, time_zone).count # => {"2013-04-16 07:00:00+00" => 80, "2013-04-17 07:00:00+00" => 70} ``` Use it with anything you can use `group` with: ```ruby Task.completed.group_by_hour(:completed_at).average(:priority) ``` Go nuts! ```ruby Request.where(page: "/home").group_by_minute(:started_at).maximum(:request_time) ``` **Note:** On Rails 4 edge, queries return a Time object (much better!) as a result of [this commit](https://github.com/rails/rails/commit/2cc09441c2de57b024b11ba666ba1e72c2b20cfe) ## Installation Add this line to your application's Gemfile: ```ruby gem 'groupdate' ``` ## Complete list - microseconds - milliseconds - second - minute - hour - day - week - month - quarter - year - decade - century - millennium ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
groupdate-0.0.2 | README.md |