Module: QTimetrap::Services::Formatters
- Defined in:
- app/services/formatters.rb
Overview
Stateless value formatters used by view models and UI rendering.
Class Method Summary collapse
Class Method Details
.seconds_to_hms(seconds) ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/services/formatters.rb', line 9 def seconds_to_hms(seconds) seconds = [seconds.to_i, 0].max hours = seconds / 3600 minutes = (seconds % 3600) / 60 secs = seconds % 60 format('%<h>02d:%<m>02d:%<s>02d', h: hours, m: minutes, s: secs) end |
.time_bounds(entry) ⇒ Object
22 23 24 25 26 |
# File 'app/services/formatters.rb', line 22 def time_bounds(entry) start_label = entry.start_time ? entry.start_time.strftime('%H:%M') : '--:--' finish_label = entry.end_time ? entry.end_time.strftime('%H:%M') : 'running' [start_label, finish_label] end |
.time_range(entry) ⇒ Object
17 18 19 20 |
# File 'app/services/formatters.rb', line 17 def time_range(entry) start_label, finish_label = time_bounds(entry) "#{start_label} - #{finish_label}" end |