Skip to content

delonnewman/time-of-day

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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