Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ankane/timerange
Time ranges for Ruby
https://github.com/ankane/timerange
Last synced: 3 months ago
JSON representation
Time ranges for Ruby
- Host: GitHub
- URL: https://github.com/ankane/timerange
- Owner: ankane
- License: mit
- Archived: true
- Created: 2014-06-21T23:43:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-03T05:48:15.000Z (over 10 years ago)
- Last Synced: 2024-07-21T22:12:33.832Z (4 months ago)
- Language: Ruby
- Size: 273 KB
- Stars: 24
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# TimeRange
Time ranges for Ruby
## Installation
Add this line to your application’s Gemfile:
```ruby
gem 'timerange'
```## Features
```ruby
time_range = TimeRange.new(7.days.ago..Time.now)
time_range.step(1.day)
time_range.expand(:week).step(1.day)TimeRange.new("2014-06-01", "2014-06-07")
TimeRange.new("2014-06-01", duration: 1.week)
TimeRange.new("2014-06-01", within: 5.minutes)
TimeRange.new(4.weeks.ago).expand_start(:week) # last 4 weeksTimeRange.today
TimeRange.yesterdayTimeRange.today + 4.weeks
TimeRange.today - 4.weeksTimeRange.bucket(:hour, user.created_at)
TimeRange.bucket(:day, user.created_at, day_start: 2) # 2 am
TimeRange.bucket(:week, user.created_at, week_start: :mon) # start weeks on Monday
TimeRange.bucket(:month, user.created_at, time_zone: "Pacific Time (US & Canada)")TimeRange.time_zone = "Pacific Time (US & Canada)" # defaults to Time.zone
```## Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- [Report bugs](https://github.com/ankane/timerange/issues)
- Fix bugs and [submit pull requests](https://github.com/ankane/timerange/pulls)
- Write, clarify, or fix documentation
- Suggest or add new features