{"id":13395086,"url":"https://github.com/ankane/groupdate","last_synced_at":"2025-11-17T14:08:53.071Z","repository":{"id":8099702,"uuid":"9514413","full_name":"ankane/groupdate","owner":"ankane","description":"The simplest way to group temporal data","archived":false,"fork":false,"pushed_at":"2025-10-22T02:24:12.000Z","size":795,"stargazers_count":3868,"open_issues_count":2,"forks_count":237,"subscribers_count":43,"default_branch":"master","last_synced_at":"2025-11-17T11:28:53.814Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2013-04-18T05:39:03.000Z","updated_at":"2025-11-17T02:20:06.000Z","dependencies_parsed_at":"2023-02-16T02:15:24.632Z","dependency_job_id":"4d64a723-9f5c-4f6d-aacb-757f84d2c620","html_url":"https://github.com/ankane/groupdate","commit_stats":{"total_commits":756,"total_committers":28,"mean_commits":27.0,"dds":"0.39814814814814814","last_synced_commit":"93db17384d8f46590af30a60ee2ee4340356fb8e"},"previous_names":[],"tags_count":64,"template":false,"template_full_name":null,"purl":"pkg:github/ankane/groupdate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fgroupdate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fgroupdate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fgroupdate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fgroupdate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/groupdate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fgroupdate/sbom","scorecard":{"id":197147,"data":{"date":"2025-08-11","repo":{"name":"github.com/ankane/groupdate","commit":"a9eba385e44164c860e9a225dae93855cd3c4553"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.4,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":10,"reason":"30 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/build.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/ankane/groupdate/build.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/ankane/groupdate/build.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/ankane/groupdate/build.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/ankane/groupdate/build.yml/master?enable=pin","Info:   0 out of   1 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   3 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-16T22:01:08.628Z","repository_id":8099702,"created_at":"2025-08-16T22:01:08.628Z","updated_at":"2025-08-16T22:01:08.628Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284893674,"owners_count":27080560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-17T02:00:06.431Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:01:41.573Z","updated_at":"2025-11-17T14:08:53.066Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","readme":"# 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://www.chartkick.com)\n\n[![Build Status](https://github.com/ankane/groupdate/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/groupdate/actions)\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 =\u003e 50,\n#   Thu, 02 Jan 2025 =\u003e 100,\n#   Fri, 03 Jan 2025 =\u003e 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://github.com/ankane/active_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 \u0026 Canada)\"\n```\n\nor\n\n```ruby\nUser.group_by_week(:created_at, time_zone: \"Pacific Time (US \u0026 Canada)\").count\n# {\n#   Sun, 05 Jan 2025 =\u003e 70,\n#   Sun, 12 Jan 2025 =\u003e 54,\n#   Sun, 19 Jan 2025 =\u003e 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\" =\u003e 10\n#   \"Feb 2025\" =\u003e 12\n# }\n```\n\nor\n\n```ruby\nUser.group_by_hour_of_day(:created_at, format: \"%-l %P\").count\n# {\n#    \"12 am\" =\u003e 15,\n#    \"1 am\"  =\u003e 11\n#    ...\n# }\n```\n\nTakes a `String`, which is passed to [strftime](https://www.strfti.me/), 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(\u0026: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\"\u003e\u003c/a\u003e\n\n### For MySQL and MariaDB\n\n[Time zone support](https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html) must be installed on the server.\n\n```sh\nmysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql\n```\n\nYou can confirm it worked with:\n\n```sql\nSELECT CONVERT_TZ(NOW(), '+00:00', 'Pacific/Honolulu');\n```\n\nIt should return the time instead of `NULL`.\n\n## History\n\nView the [changelog](https://github.com/ankane/groupdate/blob/master/CHANGELOG.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://github.com/ankane/groupdate/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/groupdate/pulls)\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","funding_links":[],"categories":["Ruby","Date and Time Processing","Gems","ActiveRecord","Uncategorized"],"sub_categories":["Articles","Query Enhancement","Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fgroupdate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fgroupdate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fgroupdate/lists"}