aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/date_ext_test.rb
blob: f9891c9358eeec348d25daa350fbefbf6ee4fdc9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require File.dirname(__FILE__) + '/../abstract_unit'

class DateExtCalculationsTest < Test::Unit::TestCase
  def test_to_s
    assert_equal "21 Feb",              Date.new(2005, 2, 21).to_s(:short)
    assert_equal "February 21, 2005",   Date.new(2005, 2, 21).to_s(:long)
    assert_equal "February 21st, 2005", Date.new(2005, 2, 21).to_s(:long_ordinal)
    assert_equal "2005-02-21",          Date.new(2005, 2, 21).to_s(:db)
    assert_equal "21 Feb 2005",         Date.new(2005, 2, 21).to_s(:rfc822)
  end

  def test_to_time
    assert_equal Time.local(2005, 2, 21), Date.new(2005, 2, 21).to_time
    assert_equal Time.local_time(2039, 2, 21), Date.new(2039, 2, 21).to_time
  end
  
  def test_to_datetime
    assert_equal DateTime.civil(2005, 2, 21), Date.new(2005, 2, 21).to_datetime
  end

  def test_to_date
    assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 21).to_date
  end

  def test_change
    assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 11).change(:day => 21)
    assert_equal Date.new(2007, 5, 11), Date.new(2005, 2, 11).change(:year => 2007, :month => 5)
  end
end