https://github.com/simon0191/date_supercharger
A nice shortcut for ActiveRecord date range queries
https://github.com/simon0191/date_supercharger
activerecord date daterange ruby ruby-gem
Last synced: about 1 year ago
JSON representation
A nice shortcut for ActiveRecord date range queries
- Host: GitHub
- URL: https://github.com/simon0191/date_supercharger
- Owner: simon0191
- License: mit
- Created: 2015-09-05T19:41:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-09-08T19:38:10.000Z (over 10 years ago)
- Last Synced: 2025-03-27T12:22:41.554Z (about 1 year ago)
- Topics: activerecord, date, daterange, ruby, ruby-gem
- Language: Ruby
- Homepage:
- Size: 156 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Date Supercharger
A nice shortcut for date queries.
Date Supercharger adds `_between`,`_between_inclusive`,`_after`, `_after_or_at`, `_before` and `_before_or_at` methods to every date/datetime field of Active Record models.
[](https://travis-ci.org/simon0191/date_supercharger)
[](https://codeclimate.com/github/simon0191/date_supercharger)
[](https://codeclimate.com/github/simon0191/date_supercharger/coverage)
[](http://badge.fury.io/rb/date_supercharger)
## Usage
### between
```ruby
Visit.created_at_between(from,to)
```
instead of
```ruby
Visit.where("created_at >= ? AND created_at < ?",from,to)
```
### between_inclusive
```ruby
Visit.created_at_between_inclusive(from,to)
```
instead of
```ruby
Visit.where("created_at >= ? AND created_at <= ?",from,to)
```
### after/before
```ruby
Visit.created_at_after(some_date)
```
instead of
```ruby
Visit.where("created_at > ?",some_date)
```
### after_or_at/before_or_at
```ruby
Visit.created_at_before_or_at(some_date)
```
instead of
```ruby
Visit.where("created_at <= ?",some_date)
```
## Installation
Add this line to your application’s Gemfile:
```ruby
gem 'date_supercharger'
```
And then execute:
```sh
bundle
```
## History
View the [changelog](https://github.com/simon0191/date_supercharger/blob/master/CHANGELOG.md)
## Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- [Report bugs](https://github.com/simon0191/date_supercharger/issues)
- Fix bugs and [submit pull requests](https://github.com/simon0191/date_supercharger/pulls)
- Write, clarify, or fix documentation
- Suggest or add new features