Module: Charming::Components::TimeDisplay
- Defined in:
- lib/charming/presentation/components/time_display.rb
Overview
TimeDisplay formats whole-second durations as clock strings: "mm:ss", or "h:mm:ss" once an hour is reached. Shared by Timer and Stopwatch.
Class Method Summary collapse
Class Method Details
.clock(total_seconds) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/charming/presentation/components/time_display.rb', line 10 def clock(total_seconds) seconds = [total_seconds.to_i, 0].max hours, remainder = seconds.divmod(3600) minutes, secs = remainder.divmod(60) return format("%d:%02d:%02d", hours, minutes, secs) if hours.positive? format("%02d:%02d", minutes, secs) end |