Sha256: 8a567b734044b24173dc1ddd18718ad623778a46f47641a9ad0bc6594999e8c7

Contents?: true

Size: 516 Bytes

Versions: 2

Compression:

Stored size: 516 Bytes

Contents

# frozen_string_literal: true

class Time

  # Formats the Time as "HH:MM:SS".  Equivalent to
  # +strftime("%H:%M:%S")+, but faster.
  #
  # @example
  #   Time.new(1999, 12, 31, 23, 59, 59).to_hms  # == "23:59:59"
  #
  # @return [String]
  def to_hms
    # Date#strftime appears to be **much** faster than Time#strftime
    # (nearly 3x faster!).  If Time#strftime becomes optimized to that
    # level in the future, it should be used instead of sprintf.
    sprintf("%02d:%02d:%02d", hour, min, sec)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
casual_support-4.0.0 lib/casual_support/time/to_hms.rb
casual_support-3.0.2 lib/casual_support/time/to_hms.rb