Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/casual_support/time/to_hms.rb,
lib/casual_support/time/to_ymd.rb
Instance Method Summary collapse
-
#to_hms ⇒ String
Formats the Time as “HH:MM:SS”.
-
#to_ymd ⇒ String
Formats the Time as “YYYY-MM-DD”.
Instance Method Details
#to_hms ⇒ String
Formats the Time as “HH:MM:SS”. Equivalent to strftime(“%H:%M:%S”), but faster.
10 11 12 13 14 15 |
# File 'lib/casual_support/time/to_hms.rb', line 10 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'.freeze, hour, min, sec) end |
#to_ymd ⇒ String
Formats the Time as “YYYY-MM-DD”. Equivalent to strftime(“%Y-%m-%d”), but faster.
10 11 12 13 14 15 |
# File 'lib/casual_support/time/to_ymd.rb', line 10 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'.freeze, year, month, day) end |