Method: Time.format_seconds
- Defined in:
- lib/openc3/core_ext/time.rb
.format_seconds(seconds) ⇒ String
Returns Seconds formatted as a human readable string with days, hours, minutes, and seconds.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/openc3/core_ext/time.rb', line 114 def self.format_seconds(seconds) result = "" mm, ss = seconds.divmod(60) hh, mm = mm.divmod(60) dd, hh = hh.divmod(24) if dd != 0 if dd == 1 result << "%d day, " % dd else result << "%d days, " % dd end end if hh != 0 if hh == 1 result << "%d hour, " % hh else result << "%d hours, " % hh end end if mm != 0 if mm == 1 result << "%d minute, " % mm else result << "%d minutes, " % mm end end if ss > 0 result << "%.2f seconds" % ss else result = result[0..-3] end result end |