Module: TimeOfDayAttr::TimeOfDay

Defined in:
lib/time_of_day_attr/time_of_day.rb

Class Method Summary collapse

Class Method Details

.convert_to_seconds(time_of_day, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/time_of_day_attr/time_of_day.rb', line 3

def self.convert_to_seconds(time_of_day, options = {})
  formats = options[:formats] || DEFAULT_FORMATS
  catch(:out_of_range) do
    formats.each do |format|
      time_format = TimeFormat.translate_format(format)
      seconds = time_of_day_to_seconds(time_of_day, time_format)
      return seconds if seconds
    end
  end
  nil
end

.omit_minutes_at_full_hour(time_of_day) ⇒ Object



15
16
17
# File 'lib/time_of_day_attr/time_of_day.rb', line 15

def self.omit_minutes_at_full_hour(time_of_day)
  time_of_day.end_with?('00') ? time_of_day[0...-3] : time_of_day
end