Class Time
In: lib/facet/time/change.rb
lib/facet/time/to_date.rb
lib/facet/time/custom_format.rb
lib/facet/time/to_s.rb
lib/facet/time/stamp.rb
lib/facet/time/to_time.rb
lib/facet/time/elapse.rb
Parent: Object

Methods

change   custom_format   elapse   stamp   to_date   to_s   to_time  

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

Returns a new Time where one or more of the elements have been changed according to the options parameter. The time options (hour, minute, sec, usec) reset cascadingly, so if only the hour is passed, then minute, sec, and usec is set to 0. If the hour and minute is passed, then sec and usec is set to 0.

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'
stamp( format = nil )

Alias for to_s

Convert a Time to a Date. Time is a superset of Date. It is the year, month and day that are carried over.

To be able to keep Dates and Times interchangeable on conversions.

[Validate]