Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Ruby
  3. ByStar

ByStar

MITRubyv4.0.1

A Ruby gem for querying ActiveRecord and Mongoid objects by time ranges like year, month, week, and day.

Visit WebsiteGitHubGitHub
1.0k stars72 forks0 contributors

What is ByStar?

ByStar is a Ruby gem that adds time-based querying capabilities to ActiveRecord and Mongoid models. It provides a rich set of scopes and methods to find database records by year, month, week, day, and other time ranges, simplifying common tasks like retrieving posts from a specific month or events happening today.

Target Audience

Ruby on Rails and Mongoid developers who need to frequently query models based on dates and times, such as those building blogs, event calendars, analytics dashboards, or any time-sensitive application.

Value Proposition

Developers choose ByStar for its clean, expressive API that reduces boilerplate code for time queries, its support for both ActiveRecord and Mongoid, and its robust handling of edge cases like timezones, offsets, and timespan objects.

Overview

Lets you find ActiveRecord + Mongoid objects by year, month, fortnight, week and more!

Use Cases

Best For

  • Querying blog posts or articles by publication month or year
  • Building event calendars with date-based filtering
  • Generating reports for specific time periods (e.g., last quarter)
  • Finding records relative to the current date (e.g., recent activity)
  • Handling timespan-based objects like multi-day events
  • Implementing pagination or navigation by time (next/previous post)

Not Ideal For

  • Projects using ORMs other than ActiveRecord or Mongoid, such as Sequel or ROM
  • Applications where time-based queries are simple enough for raw SQL or basic ActiveRecord scopes
  • Systems requiring sub-second precision or nanosecond-level time filtering

Pros & Cons

Pros

Expressive Query DSL

Provides intuitive methods like `by_year` and `past_week` that eliminate complex SQL, as shown in examples for querying posts by date without manual condition building.

Comprehensive Time Range Support

Covers everything from days to years, including relative scopes and timespan handling, with options for offsets and timezones detailed in the README's usage sections.

Dual ORM Compatibility

Works seamlessly with both ActiveRecord and Mongoid, requiring only a simple `include Mongoid::ByStar` for Mongoid models, as per installation instructions.

Advanced Timespan Features

Supports objects with start and end times, offering permissive or strict matching and configurable :index_scope for database performance, though setup is manual.

Cons

Complex Index Configuration

For timespan objects, proper database indexing requires understanding and setting the :index_scope option, which the README admits is not automated and can be error-prone.

External Gem Dependency

Natural language date parsing depends on the Chronic gem, which must be explicitly added to the Gemfile since version 2.2.0, adding maintenance overhead.

Date Handling Caveats

The README warns of issues with between_times for dates (see Issue #49), potentially leading to unexpected behavior in edge cases without clear resolutions.

Frequently Asked Questions

Quick Stats

Stars1,046
Forks72
Contributors0
Open Issues8
Last commit3 years ago
CreatedSince 2008

Tags

#mongoid#query-builder#orm#database#rails#ruby-gem#activerecord#timezone-handling

Built With

R
Ruby
M
Mongoid
A
ActiveRecord

Links & Resources

Website

Included in

Ruby14.1k
Auto-fetched 18 hours ago

Related Projects

groupdategroupdate

The simplest way to group temporal data

Stars3,889
Forks242
Last commit25 days ago
chronicchronic

Chronic is a pure Ruby natural language date parser.

Stars3,256
Forks450
Last commit2 years ago
ice_cubeice_cube

Ruby Date Recurrence Library - Allows easy creation of recurrence rules and fast querying

Stars2,470
Forks354
Last commit6 months ago
local_timelocal_time

Rails engine for cache-friendly, client-side local time

Stars2,001
Forks126
Last commit11 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub