Sha256: 8b0af7fca245fde95973db0e52c3195e7ed29cb81c863dac0072800b146d0e90
Contents?: true
Size: 828 Bytes
Versions: 26
Compression:
Stored size: 828 Bytes
Contents
require 'date' class Date # An enhanched #to_s method that cane take an optional # format flag of :short or :long. def stamp(format = nil) case format when :short strftime("%e %b").strip when :long strftime("%B %e, %Y").strip else strftime("%Y-%m-%d") # standard to_s end end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCDate < Test::Unit::TestCase def setup @d = Date.civil( 2005, 04, 20 ) end def test_stamp_1 assert_equal( "2005-04-20", @d.stamp ) end def test_stamp_2 assert_equal( "20 Apr", @d.stamp(:short) ) end def test_stamp_3 assert_equal( "April 20, 2005", @d.stamp(:long) ) end end =end
Version data entries
26 entries across 26 versions & 1 rubygems