Sha256: 1965d0a61fe9f51ca101fc235db81e6ddd0dc759a2fb0f982878295f1a19ef77

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'test/unit'

require 'facet/time/custom_format'
require 'facet/time/elapse'
require 'facet/time/stamp'
require 'facet/time/to_s'
require 'facet/time/to_time'
require 'facet/time/to_date'


class TC_Time < Test::Unit::TestCase

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

  def test_elpase
    t = Time.elapse { sleep 1 }
    assert( (t > 0.9) && (t < 2.1 ))
  end

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

  # stamp
  
  def test_stamp
    assert_equal( "Wed Apr 20 15:37:00 EDT 2005", @t.stamp )
  end

  # to_date
  
  def test_to_date
    assert_instance_of( ::Date, @t.to_date )
  end

  # to_s
    
  def test_to_s
    assert_equal( "Wed Apr 20 15:37:00 EDT 2005", @t.to_s )
  end
  
  # to_time
  
  def test_to_time
    assert_instance_of( ::Time, @t.to_time )
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-0.7.0 test/time/tc_time.rb
facets-0.7.1 test/time/tc_time.rb
facets-0.7.2 test/time/tc_time.rb