github.com/billaul/period

Smart-Period aims to simplify Time-range manipulation

Open this visualization on its own page →

Contributors

2

Lines of Code

183

From

2019-05-09

To

2020-12-28

About billaul/period

Smart-Period is a Ruby gem designed to simplify working with time ranges, particularly in Rails applications and scenarios involving user input. The gem handles period manipulation while always rounding start and end times to the beginning and end of the day respectively, making it suitable for applications that work with full-day time ranges rather than precise timestamps.

The gem provides two main approaches for creating and manipulating time periods: FreePeriod for flexible, arbitrary date ranges that can be shifted forward or backward, and StandardPeriod for strictly defined periods like days, weeks, months, quarters, and years. StandardPeriod objects maintain their type when manipulated and include convenient methods like `.next` and `.prev` for navigation, as well as shortcuts like `.this_month`, `.last_quarter`, and `.tomorrow` for quick access to common periods.

Smart-Period integrates seamlessly with ActiveRecord and Rails controllers, inheriting from Ruby's Range class to work natively in database queries. It supports both HasMany relationships (breaking periods into smaller units) and BelongsTo relationships (finding parent periods), includes internationalization for English and French, handles timezone considerations automatically, and follows ISO 8601 standards for week calculations. The project is no longer actively maintained, with the author directing users to its successor, ActivePeriod, for new features like endless-period support.

Share this video