Sha256: 3df76c074e8ad178373da5ffbba8eba96228bfcba5a12d90f0aef5ead08930a4
Contents?: true
Size: 918 Bytes
Versions: 25
Compression:
Stored size: 918 Bytes
Contents
# frozen_string_literal: true module Doing ## ## Number helpers ## class ::Numeric ## ## Format human readable time from seconds ## ## @param seconds [Integer] Seconds ## 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 ## ## Format seconds as natural language time string ## ## @param format [Symbol] The format to output ## (:dhm, :hm, :m, :clock, :natural) ## def time_string(format: :dhm) format_time(human: true).time_string(format: format) end end end
Version data entries
25 entries across 25 versions & 1 rubygems