#--
# CHANGE 2006-12-10 <transfire@gmail.com>
# * Added FORMAT constant to make more flexible. 
#++

class Time

  FORMAT = {
    :db      => "%Y-%m-%d %H:%M:%S",
    :dbase   => "%Y-%m-%d %H:%M:%S",
    :datbase => "%Y-%m-%d %H:%M:%S",
    :utc     => "%Y-%m-%d %H:%M:%S",
    :short   => "%d %b %H:%M",
    :long    => "%B %d, %Y %H:%M",
    :day1st  => "%d-%m-%Y %H:%M",
    :dmYHM   => "%d-%m-%Y %H:%M",
    :rfc822  => "%a, %d %b %Y %H:%M:%S %z",
    nil      => "%a %b %d %H:%M:%S %Z %Y"
  }

  def stamp( fmt = nil )
    unless String === fmt
      fmt = FORMAT[fmt]
    end
    strftime(fmt).strip
  end

  def self.stamp(*args)
    now.stamp(*args)
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'
  require 'time'

  class TCTime < Test::Unit::TestCase

    def setup
      @t = Time.parse('4/02/2005 15:37')
    end

    def test_001
      assert_equal( "Sat Apr 02 15:37:00 EST 2005", @t.stamp )
    end

    def test_002
      assert_equal( "April 02, 2005 15:37", @t.stamp(:long) )
    end

    def test_003
      assert_equal( "02 Apr 15:37", @t.stamp(:short) )
    end

  end

=end

