Enhance your Ruby project with time-based ranges.
ruby-time_range gem and require it in your project.
gem install ruby-time_range
or include the gem in your Gemfile and
TimeRanges can be easily created by calling
#to_time_range on any normal Range of Times.
(Time.now .. (Time.now + 60)).to_time_range
or use the constructor:
TimeRange.new(Time.now, (Time.now + 60))
TimeRange extends the regular
Range with useful methods that apply to time-based objects. Where appropriate, it reimplements
Range methods as they should apply to Time-based ranges.
TimeRanges can be compared and examined in useful ways.
TimeRange#durationThe duration of the TimeRange in seconds.
TimeRange#encapsulates?Check if one TimeRange encapsulates another entirely.
TimeRange#encapsulated_by?Check if one TimeRange is encapsulated by another entirely...
TimeRange#overlaps?Check if one TimeRange overlaps another in any way.
TimeRange#overlap_withReturns the overlap between two TimeRanges, as a new TimeRange.
TimeRange#datesReturns a range of dates in the TimeRange.
Existing Range methods; such as
#==, etc, are still available, having been reimplemented where appropriate to maintain consistency in a temporal context.
For full API documentation see the rubydocs.
- Fork and clone the project.
git checkout master.
git checkout -ba topic branch for your fix/addition.
- Make and commit your changes.
- Push to your fork and pull request against master.
- Contributions will not be accepted without tests.
- Please read and check Github issues and pending pull requests before submitting new code.
- If adding a feature please post a new issue for discussion first.
Thanks for taking the time to contribute!
ruby-time_range is Copyright ©2016 Jon Hope. It is free software, and may be redistributed under the terms specified in the LICENSE file.