Class Time
In: lib/facet/time/custom_format.rb
lib/facet/time/elapse.rb
Parent: Object

Methods

Constants

MONTH_NAMES = %w| January February March April May June July August September October November December |
DAY_NAMES = %w| Sunday Monday Tuesday Wednesday Thursday Friday Saturday |

Public Class methods

Tracks the elapse time of a code block.

  require 'facet/time/elapse'

  Time.elapse { sleep 1 }  #=> 0.999188899993896

Public Instance methods

Replaces every token in formatString with its corresponding value. See the table below.

   token:     description:             example:
   #YYYY#     4-digit year             2004
   #YY#       2-digit year             04
   #MMMM#     full month name          February
   #MMM#      3-letter month name      Feb
   #MM#       2-digit month number     02
   #M#        month number             2
   #DDDD#     full weekday name        Wednesday
   #DDD#      3-letter weekday name    Wed
   #DD#       2-digit day number       09
   #D#        day number               9
   #th#       day ordinal suffix       nd
   #hhh#      military/24-based hour   17
   #hh#       2-digit hour             05
   #h#        hour                     5
   #mm#       2-digit minute           07
   #m#        minute                   7
   #ss#       2-digit second           09
   #s#        second                   9
   #ampm#     "am" or "pm"             pm
   #AMPM#     "AM" or "PM"             PM

Non-tokens are left untouched in the output string.

  require 'facet/time/custom_format'

  time = Time.parse('2/3/2004 15:37')
  time.custom_format('#DDDD#, #MMMM# #D##th# @ #h#:#mm##ampm#')
     #=>  'Tuesday, February 3rd @ 3:37pm'
  time.custom_format('#YYYY#-#MMM#-#D#')
     #=>  '2004-Feb-3'
  time.custom_format('#MM#/#DD#/#YY#')
     #=>  '02/03/04'

[Validate]