Module: TimeRounder
- Defined in:
- lib/time_rounder.rb,
lib/time_rounder/version.rb,
lib/time_rounder/rounded_time.rb,
lib/time_rounder/load_schedule.rb,
lib/time_rounder/end_before_start.rb,
lib/time_rounder/schedule_not_found.rb,
lib/time_rounder/schedule/fifteen_minute.rb,
lib/time_rounder/rounded_time_from_seconds.rb
Overview
TimeRounder is a library to round time.
Defined Under Namespace
Modules: LoadSchedule, Schedule Classes: EndBeforeStart, RoundedTime, RoundedTimeFromSeconds, ScheduleNotFound
Constant Summary collapse
- VERSION =
'0.5.0'.freeze
Class Method Summary collapse
-
.difference_between_rounded_times(start_time, end_time, schedule = 15) ⇒ Object
Calculates the difference between 2 rounded times.
-
.difference_between_times(start_time, end_time, schedule = 15) ⇒ Object
Calculates the difference between 2 standard times.
-
.rounded_time(time, schedule = 15) ⇒ Object
Takes a DateTime/Time object and returns the time to the nearest quarter hour.
-
.seconds_to_hours(seconds, schedule = 15) ⇒ Object
Takes number of seconds and returns hours and partial hours in decimal form.
Class Method Details
.difference_between_rounded_times(start_time, end_time, schedule = 15) ⇒ Object
Calculates the difference between 2 rounded times
26 27 28 29 30 31 |
# File 'lib/time_rounder.rb', line 26 def self.difference_between_rounded_times(start_time, end_time, schedule = 15) s = TimeRounder::RoundedTime.new(start_time, schedule).rounded_time e = TimeRounder::RoundedTime.new(end_time, schedule).rounded_time seconds = (e - s).to_i TimeRounder::RoundedTimeFromSeconds.new(seconds, schedule).rounded_time end |
.difference_between_times(start_time, end_time, schedule = 15) ⇒ Object
Calculates the difference between 2 standard times
35 36 37 38 |
# File 'lib/time_rounder.rb', line 35 def self.difference_between_times(start_time, end_time, schedule = 15) seconds = (end_time - start_time).to_i TimeRounder::RoundedTimeFromSeconds.new(seconds, schedule).rounded_time end |
.rounded_time(time, schedule = 15) ⇒ Object
Takes a DateTime/Time object and returns the time to the nearest quarter hour
20 21 22 |
# File 'lib/time_rounder.rb', line 20 def self.rounded_time(time, schedule = 15) TimeRounder::RoundedTime.new(time, schedule).rounded_time end |
.seconds_to_hours(seconds, schedule = 15) ⇒ Object
Takes number of seconds and returns hours and partial hours in decimal form.
12 13 14 |
# File 'lib/time_rounder.rb', line 12 def self.seconds_to_hours(seconds, schedule = 15) TimeRounder::RoundedTimeFromSeconds.new(seconds, schedule).rounded_time end |