Skip to content

MatthewSchultz/activerecord_time_scopes

Repository files navigation

Activerecord Time Scopes

A simple gem that allows some of the most common time-scopes for ActiveRecord objects.

Installation

Add this line to your application's Gemfile:

gem 'activerecord_time_scopes', '>= 0.0.1'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activerecord_time_scopes

Usage

This plugin enables the following methods:

[created | updated] _ [before | after | between | today | yesterday | this_week | last_week | this_month | last_month | this_year | last_year]

You can pass either datetime objects or ActiveRecord objects - if you pass an activerecord object, the relevant method (created/updated_at) will be used to search.

Some Examples:

SomeModel.created_after(Time.zone.now - 4.days)
SomeModel.updated_before(Time.zone.now)
SomeRecord.created_after(@user)
User.updated_between(Time.zone.now - 3.days, Time.zone.now - 2.days)
Order.created_today
Order.created_yesterday
Account.created_this_year
Account.created_last_year

License

The gem is available as open source under the terms of the MIT License.

About

A collection of time scopes for activerecord, including created_after/created_before/updated_after/etc

Resources

License

Stars

Watchers

Forks

Packages

No packages published