Class: TimeOfDayAttr::TimeOfDay
- Inherits:
-
Struct
- Object
- Struct
- TimeOfDayAttr::TimeOfDay
- Defined in:
- lib/time_of_day_attr/time_of_day.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value
2 3 4 |
# File 'lib/time_of_day_attr/time_of_day.rb', line 2 def value @value end |
Instance Method Details
#to_seconds(time_format) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/time_of_day_attr/time_of_day.rb', line 3 def to_seconds(time_format) time = Time.strptime(value, 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.change(month: 1, day: 1) seconds = time.seconds_since_midnight.to_i if seconds.zero? && value.starts_with?('24') 24.hours.to_i else seconds end end |