A Ruby object that represents a given time-of-day separate from any Date information. Makes it easy to perform work time calculations.
(TimeOfDay('1:12 PM') + 1) # => 1:13 PM
(TimeOfDay('1:12 PM') - 1) # => 1:11 PM
(TimeOfDay('8:00 AM')..TimeOfDay('5:00 PM')).to_a # => [8:00 AM, 8:15 AM, 8:30 AM, ...]
TimeOfDay('8:00 AM') < TimeOfDay('8:03 AM') # => true
# Can compare to Time objects
TimeOfDay.now == Time.now # true
TimeOfDay.now > Time.now # false
TimeOfDay('8:24 AM') in [hour, *]
hour # => 8
TimeOfDay('10:43 AM').round => min:
min # => 45
TimeOfDay('8:17 AM').round # => 8:15 AM
TimeOfDay('8:17 AM').round(30) # => 8:30 AM
TimeSeries('8:34 AM', '12:05 PM').hours.to_f # => 3.5
TimeSeries('8:34 AM', '12:05 PM', '1:34 PM', '5:23 PM').hours.to_f # => 7.5
TimeSeries('8:34 AM', '12:05 PM', '1:34 PM', '5:23 PM').interval_time.to_f # => 450.0 (in minutes)
TimeSeries('8:34 AM', '12:05 PM', '1:34 PM', '5:23 PM').gap_time.to_f # => 90.0 (in minutes)
Add this line to your application's Gemfile:
gem 'time-of-day'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install time-of-day
The gem is available as open source under the terms of the MIT License.