Timerage
Time Ranges that are actually useful.
Installation
Add this line to your application's Gemfile:
gem 'timerage'
And then execute:
$ bundle
Or install it yourself as:
$ gem install timerage
Usage
require 'timerage'
Coercion to Time (related) objects
a_time = Timerage("2016-01-18T22:25:37Z")
Timerage(a_time)
Timerage("2016-01-18T21:25:37+00:00/2016-01-18T22:25:37+00:00")
interval = Timerage((a_time-3600)...a_time)
Stepping over a time inteval
interval.step(30*60).map { |time| time }
Slicing a time interval
interval.slice(30*60).map { |time| time }
ISO 8601 output
interval.iso8601
Comparisons
Supports most range/set comparisons
#overlap?
#cover?
#adjacent_to?
#==
Concatenation
interval + Timerage("2016-01-18T20:25:37+00:00/2016-01-18T21:25:37+00:00")
Duration
interval.duration
Gotchas
This doesn't fix the #each
method to do anything useful, you still can't
blindly iterate over a range of time. You can use the #step(seconds)
method
however, which makes more sense anyway. (what does it even mean to iterate
over a time range? What is the next time after "now"? How many steps should we
take?)
Contributing
- Fork it ( http://github.com/cschneid/timerage/fork )
- Create your feature branch (
git checkout -b my-new-feature
)
- Commit your changes (
git commit -am 'Add some feature'
)
- Push to the branch (
git push origin my-new-feature
)
- Create new Pull Request