Module: Doing::ChronifyNumeric
- Included in:
- Numeric
- Defined in:
- lib/doing/chronify/numeric.rb
Overview
Number helpers
Instance Method Summary collapse
-
#format_time(human: false) ⇒ Object
Format human readable time from seconds.
-
#time_string(format: :dhm) ⇒ Object
Format seconds as natural language time string.
Instance Method Details
#format_time(human: false) ⇒ Object
Format human readable time from seconds
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/doing/chronify/numeric.rb', line 14 def format_time(human: false) return [0, 0, 0] if nil? seconds = dup.to_i minutes = (seconds / 60).to_i hours = (minutes / 60).to_i if human minutes = (minutes % 60).to_i [0, hours, minutes] else days = (hours / 24).to_i hours = (hours % 24).to_i minutes = (minutes % 60).to_i [days, hours, minutes] end end |
#time_string(format: :dhm) ⇒ Object
Format seconds as natural language time string
37 38 39 |
# File 'lib/doing/chronify/numeric.rb', line 37 def time_string(format: :dhm) format_time(human: true).time_string(format: format) end |