Skip to content

A Ruby object that represents a given time-of-day separate from any Date information. Makes it easy to perform work time calculations.

License

Notifications You must be signed in to change notification settings

delonnewman/time-of-day

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TimeOfDay

A Ruby object that represents a given time-of-day separate from any Date information. Makes it easy to perform work time calculations.

Synopsis

Arithmetic

(TimeOfDay('1:12 PM') + 1) # => 1:13 PM

(TimeOfDay('1:12 PM') - 1) # => 1:11 PM

Range Support

(TimeOfDay('8:00 AM')..TimeOfDay('5:00 PM')).to_a # => [8:00 AM, 8:15 AM, 8:30 AM, ...]

Comparable

TimeOfDay('8:00 AM') < TimeOfDay('8:03 AM') # => true

# Can compare to Time objects
TimeOfDay.now == Time.now # true
TimeOfDay.now > Time.now # false

Pattern Matching

TimeOfDay('8:24 AM') in [hour, *]
hour # => 8

TimeOfDay('10:43 AM').round => min:
min # => 45

Rounding

TimeOfDay('8:17 AM').round # => 8:15 AM

TimeOfDay('8:17 AM').round(30) # => 8:30 AM

Rounded time calculations

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)

Installation

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

See Also

License

The gem is available as open source under the terms of the MIT License.

About

A Ruby object that represents a given time-of-day separate from any Date information. Makes it easy to perform work time calculations.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages