Class: TimeOfDayAttr::Seconds

Inherits:
Struct
  • Object
show all
Defined in:
lib/time_of_day_attr/seconds.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#value ⇒ Object

Returns the value of attribute value

Returns:

  • (Object) —

    the current value of value



2
3
4
# File 'lib/time_of_day_attr/seconds.rb', line 2

def value
  @value
end

Instance Method Details

#to_time_of_day(time_format) ⇒ Object



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

def to_time_of_day(time_format)
  # Switch to beginning of year to prevent wrong conversion on the day of time change
  # see https://en.wikipedia.org/wiki/Daylight_saving_time
  time = Time.now.beginning_of_year.at_midnight + value.seconds

  time_of_day = time.strftime(time_format)

  if 24.hours.to_i == value
    time_of_day.gsub(' 0', '24')
  else
    time_of_day
  end
end