0.0
No commit activity in last 3 years
No release in over 3 years
Enhance your Ruby project with time-based ranges.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.11
~> 10.0
 Project Readme

TimeRange

Build Status Code Climate Test Coverage

Enhance your Ruby project with time-based ranges.

Installation

Install the ruby-time_range gem and require it in your project.

gem install ruby-time_range

or include the gem in your Gemfile and bundle install.

gem 'ruby-time_range'

Usage

require 'time_range'

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))

About

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#duration The 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_with Returns the overlap between two TimeRanges, as a new TimeRange.
  • TimeRange#dates Returns a range of dates in the TimeRange.

Existing Range methods; such as #max, #min, #cover?, #==, etc, are still available, having been reimplemented where appropriate to maintain consistency in a temporal context.

For full API documentation see the rubydocs.

Contributing

  • Fork and clone the project.
  • git checkout master.
  • git checkout -b a topic branch for your fix/addition.
  • Run bundle.
  • Make and commit your changes.
  • Push to your fork and pull request against master.

Note:

  • 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!

License

ruby-time_range is Copyright ©2016 Jon Hope. It is free software, and may be redistributed under the terms specified in the LICENSE file.