[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7805":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":20,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":16,"starSnapshotCount":16,"syncStatus":15,"lastSyncTime":26,"discoverSource":27},7805,"groupdate","ankane\u002Fgroupdate","ankane","The simplest way to group temporal data","",null,"Ruby",3886,238,41,2,0,1,59.24,"MIT License",false,"master",[],"2026-06-12 04:00:35","# Groupdate\n\nThe simplest way to group by:\n\n- day\n- week\n- hour of the day\n- and more (complete list below)\n\n:tada: Time zones - including daylight saving time - supported!! **the best part**\n\n:cake: Get the entire series - **the other best part**\n\nSupports PostgreSQL, MySQL, MariaDB, SQLite, and Redshift, plus arrays and hashes\n\n:cupid: Goes hand in hand with [Chartkick](https:\u002F\u002Fwww.chartkick.com)\n\n[![Build Status](https:\u002F\u002Fgithub.com\u002Fankane\u002Fgroupdate\u002Factions\u002Fworkflows\u002Fbuild.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fankane\u002Fgroupdate\u002Factions)\n\n## Installation\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"groupdate\"\n```\n\nFor MySQL and MariaDB, also follow [these instructions](#additional-instructions).\n\n## Getting Started\n\n```ruby\nUser.group_by_day(:created_at).count\n# {\n#   Wed, 01 Jan 2025 => 50,\n#   Thu, 02 Jan 2025 => 100,\n#   Fri, 03 Jan 2025 => 34\n# }\n```\n\nResults are returned in ascending order by default, so no need to sort.\n\nYou can group by:\n\n- second\n- minute\n- hour\n- day\n- week\n- month\n- quarter\n- year\n\nand\n\n- minute_of_hour\n- hour_of_day\n- day_of_week (Sunday = 0, Monday = 1, etc)\n- day_of_month\n- day_of_year\n- month_of_year\n\nUse it anywhere you can use `group`. Works with `count`, `sum`, `minimum`, `maximum`, and `average`. For `median` and `percentile`, check out [ActiveMedian](https:\u002F\u002Fgithub.com\u002Fankane\u002Factive_median).\n\n### Time Zones\n\nThe default time zone is `Time.zone`.  Change this with:\n\n```ruby\nGroupdate.time_zone = \"Pacific Time (US & Canada)\"\n```\n\nor\n\n```ruby\nUser.group_by_week(:created_at, time_zone: \"Pacific Time (US & Canada)\").count\n# {\n#   Sun, 05 Jan 2025 => 70,\n#   Sun, 12 Jan 2025 => 54,\n#   Sun, 19 Jan 2025 => 80\n# }\n```\n\nTime zone objects also work. To see a list of available time zones in Rails, run `rake time:zones:all`.\n\n### Week Start\n\nWeeks start on Sunday by default. Change this with:\n\n```ruby\nGroupdate.week_start = :monday\n```\n\nor\n\n```ruby\nUser.group_by_week(:created_at, week_start: :monday).count\n```\n\n### Day Start\n\nYou can change the hour days start with:\n\n```ruby\nGroupdate.day_start = 2 # 2 am - 2 am\n```\n\nor\n\n```ruby\nUser.group_by_day(:created_at, day_start: 2).count\n```\n\n### Time Range\n\nTo get a specific time range, use:\n\n```ruby\nUser.group_by_day(:created_at, range: 2.weeks.ago.midnight..Time.now).count\n```\n\nTo expand the range to the start and end of the time period, use:\n\n```ruby\nUser.group_by_day(:created_at, range: 2.weeks.ago..Time.now, expand_range: true).count\n```\n\nTo get the most recent time periods, use:\n\n```ruby\nUser.group_by_week(:created_at, last: 8).count # last 8 weeks\n```\n\nTo exclude the current period, use:\n\n```ruby\nUser.group_by_week(:created_at, last: 8, current: false).count\n```\n\n### Order\n\nYou can order in descending order with:\n\n```ruby\nUser.group_by_day(:created_at, reverse: true).count\n```\n\n### Keys\n\nKeys are returned as date or time objects for the start of the period.\n\nTo get keys in a different format, use:\n\n```ruby\nUser.group_by_month(:created_at, format: \"%b %Y\").count\n# {\n#   \"Jan 2025\" => 10\n#   \"Feb 2025\" => 12\n# }\n```\n\nor\n\n```ruby\nUser.group_by_hour_of_day(:created_at, format: \"%-l %P\").count\n# {\n#    \"12 am\" => 15,\n#    \"1 am\"  => 11\n#    ...\n# }\n```\n\nTakes a `String`, which is passed to [strftime](https:\u002F\u002Fwww.strfti.me\u002F), or a `Symbol`, which is looked up by `I18n.localize` in `i18n` scope 'time.formats', or a `Proc`.  You can pass a locale with the `locale` option.\n\n### Series\n\nThe entire series is returned by default. To exclude points without data, use:\n\n```ruby\nUser.group_by_day(:created_at, series: false).count\n```\n\nOr change the default value with:\n\n```ruby\nUser.group_by_day(:created_at, default_value: \"missing\").count\n```\n\n### Dynamic Grouping\n\n```ruby\nUser.group_by_period(:day, :created_at).count\n```\n\nLimit groupings with the `permit` option.\n\n```ruby\nUser.group_by_period(params[:period], :created_at, permit: [\"day\", \"week\"]).count\n```\n\nRaises an `ArgumentError` for unpermitted periods.\n\n### Custom Duration\n\nTo group by a specific number of minutes or seconds, use:\n\n```ruby\nUser.group_by_minute(:created_at, n: 10).count # 10 minutes\n```\n\n### Date Columns\n\nIf grouping on date columns which don’t need time zone conversion, use:\n\n```ruby\nUser.group_by_week(:created_on, time_zone: false).count\n```\n\n### Default Scopes\n\nIf you use Postgres and have a default scope that uses `order`, you may get a `column must appear in the GROUP BY clause` error (just like with Active Record’s `group` method). Remove the `order` scope with:\n\n```ruby\nUser.unscope(:order).group_by_day(:count).count\n```\n\n## Arrays and Hashes\n\n```ruby\nusers.group_by_day { |u| u.created_at } # or group_by_day(&:created_at)\n```\n\nSupports the same options as above\n\n```ruby\nusers.group_by_day(time_zone: time_zone) { |u| u.created_at }\n```\n\nGet the entire series with:\n\n```ruby\nusers.group_by_day(series: true) { |u| u.created_at }\n```\n\nCount\n\n```ruby\nusers.group_by_day { |u| u.created_at }.to_h { |k, v| [k, v.count] }\n```\n\n## Additional Instructions\n\n\u003Ca name=\"for-mysql\">\u003C\u002Fa>\n\n### For MySQL and MariaDB\n\n[Time zone support](https:\u002F\u002Fdev.mysql.com\u002Fdoc\u002Frefman\u002F8.0\u002Fen\u002Ftime-zone-support.html) must be installed on the server.\n\n```sh\nmysql_tzinfo_to_sql \u002Fusr\u002Fshare\u002Fzoneinfo | mysql -u root mysql\n```\n\nYou can confirm it worked with:\n\n```sql\nSELECT CONVERT_TZ(NOW(), '+00:00', 'Pacific\u002FHonolulu');\n```\n\nIt should return the time instead of `NULL`.\n\n## History\n\nView the [changelog](https:\u002F\u002Fgithub.com\u002Fankane\u002Fgroupdate\u002Fblob\u002Fmaster\u002FCHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https:\u002F\u002Fgithub.com\u002Fankane\u002Fgroupdate\u002Fissues)\n- Fix bugs and [submit pull requests](https:\u002F\u002Fgithub.com\u002Fankane\u002Fgroupdate\u002Fpulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development and testing, check out the [Contributing Guide](CONTRIBUTING.md).\n","Groupdate 是一个用于按时间分组数据的 Ruby 库，支持多种时间单位如天、周、小时等。其核心功能包括对时区（包括夏令时）的支持和获取整个时间序列的能力，使得处理时间数据变得简单而高效。该库兼容 PostgreSQL, MySQL, MariaDB, SQLite 和 Redshift 等多种数据库，并且可以与数组和哈希一起使用。特别地，它与 Chartkick 结合使用可轻松生成图表。适用于需要按不同时间维度统计分析的应用场景，比如用户行为分析、销售数据报告等领域。","2026-06-11 03:14:28","top_language"]