class Time
Public Instance Methods
to_hms()
click to toggle source
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]
# File lib/casual_support/time/to_hms.rb, line 12 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
to_ymd()
click to toggle source
Formats the Time
as “YYYY-MM-DD”. Equivalent to +strftime(“%Y-%m-%d”)+, but faster.
@example
Time.new(1999, 12, 31, 23, 59, 59).to_ymd # == "1999-12-31"
@return [String]
# File lib/casual_support/time/to_ymd.rb, line 12 def to_ymd # 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("%04d-%02d-%02d", year, month, day) end