Time-Of-Day
01 Sep 2020
https://github.com/delonnewman/time-of-day - An open-source Ruby library developed while at UNM Hospitals. It’s an object that represents a given time-of-day separate from any Date information. Making it easy to perform work time calculations.
# Arithmetic
(TimeOfDay('1:12PM') + 1).to_s # => "1:13 PM"
(TimeOfDay('1:12PM') - 1).to_s # => "1:12 PM"
# Range Support
(TimeOfDay('8:00AM')..TimeOfDay('5:00PM')).map(&:to_s) # => ["8:00 AM", "8:15 AM", "8:30 AM", ...]
# Rounding the nearest 15min interval
TimeOfDay('8:34AM').round.to_s # => "8:30 AM"
# Rounded time calculations
TimeOfDay::Series('8:34AM', '12:05PM').hours.to_f # => 3.5
TimeOfDay::Series('8:34AM', '12:05PM', '1:34PM', '5:23PM').hours.to_f # => 7.5
TimeOfDay::Series('8:34AM', '12:05PM', '1:34PM', '5:23PM').work_time.to_f # 450.0 (in minutes)
TimeOfDay::Series('8:34AM', '12:05PM', '1:34PM', '5:23PM').break_time.to_f # 90.0 (in minutes)