aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb24
-rw-r--r--activesupport/test/core_ext/date_time_ext_test.rb16
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb18
3 files changed, 58 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index 6e91fdedce..760d138623 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -175,6 +175,18 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal Date.new(1582,10,4), Date.new(1583,10,14).prev_year
end
+ def test_last_year
+ assert_equal Date.new(2004,6,5), Date.new(2005,6,5).last_year
+ end
+
+ def test_last_year_in_leap_years
+ assert_equal Date.new(1999,2,28), Date.new(2000,2,29).last_year
+ end
+
+ def test_last_year_in_calendar_reform
+ assert_equal Date.new(1582,10,4), Date.new(1583,10,14).last_year
+ end
+
def test_next_year
assert_equal Date.new(2006,6,5), Date.new(2005,6,5).next_year
end
@@ -245,6 +257,14 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal Date.new(2010,2,27), Date.new(2010,3,4).prev_week(:saturday)
end
+ def test_last_week
+ assert_equal Date.new(2005,5,9), Date.new(2005,5,17).last_week
+ assert_equal Date.new(2006,12,25), Date.new(2007,1,7).last_week
+ assert_equal Date.new(2010,2,12), Date.new(2010,2,19).last_week(:friday)
+ assert_equal Date.new(2010,2,13), Date.new(2010,2,19).last_week(:saturday)
+ assert_equal Date.new(2010,2,27), Date.new(2010,3,4).last_week(:saturday)
+ end
+
def test_next_week
assert_equal Date.new(2005,2,28), Date.new(2005,2,22).next_week
assert_equal Date.new(2005,3,4), Date.new(2005,2,22).next_week(:friday)
@@ -265,6 +285,10 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal Date.new(2004, 2, 29), Date.new(2004, 3, 31).prev_month
end
+ def test_last_month_on_31st
+ assert_equal Date.new(2004, 2, 29), Date.new(2004, 3, 31).last_month
+ end
+
def test_yesterday_constructor
assert_equal Date.current - 1, Date.yesterday
end
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb
index 57b5b95a66..cd8cb5d18b 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -159,6 +159,10 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal DateTime.civil(2004,6,5,10), DateTime.civil(2005,6,5,10,0,0).prev_year
end
+ def test_last_year
+ assert_equal DateTime.civil(2004,6,5,10), DateTime.civil(2005,6,5,10,0,0).last_year
+ end
+
def test_next_year
assert_equal DateTime.civil(2006,6,5,10), DateTime.civil(2005,6,5,10,0,0).next_year
end
@@ -232,6 +236,14 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal DateTime.civil(2006,11,15), DateTime.civil(2006,11,23,0,0,0).prev_week(:wednesday)
end
+ def test_last_week
+ assert_equal DateTime.civil(2005,2,21), DateTime.civil(2005,3,1,15,15,10).last_week
+ assert_equal DateTime.civil(2005,2,22), DateTime.civil(2005,3,1,15,15,10).last_week(:tuesday)
+ assert_equal DateTime.civil(2005,2,25), DateTime.civil(2005,3,1,15,15,10).last_week(:friday)
+ assert_equal DateTime.civil(2006,10,30), DateTime.civil(2006,11,6,0,0,0).last_week
+ assert_equal DateTime.civil(2006,11,15), DateTime.civil(2006,11,23,0,0,0).last_week(:wednesday)
+ end
+
def test_next_week
assert_equal DateTime.civil(2005,2,28), DateTime.civil(2005,2,22,15,15,10).next_week
assert_equal DateTime.civil(2005,3,4), DateTime.civil(2005,2,22,15,15,10).next_week(:friday)
@@ -247,6 +259,10 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 3, 31).prev_month
end
+ def test_last_month_on_31st
+ assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 3, 31).last_month
+ end
+
def test_xmlschema
assert_match(/^1880-02-28T15:15:10\+00:?00$/, DateTime.civil(1880, 2, 28, 15, 15, 10).xmlschema)
assert_match(/^1980-02-28T15:15:10\+00:?00$/, DateTime.civil(1980, 2, 28, 15, 15, 10).xmlschema)
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index eda8066579..c542acca68 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -198,6 +198,10 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).prev_year
end
+ def test_last_year
+ assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).last_year
+ end
+
def test_next_year
assert_equal Time.local(2006,6,5,10), Time.local(2005,6,5,10,0,0).next_year
end
@@ -505,6 +509,16 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal Time.local(2006,11,15), Time.local(2006,11,23,0,0,0).prev_week(:wednesday)
end
end
+
+ def test_last_week
+ with_env_tz 'US/Eastern' do
+ assert_equal Time.local(2005,2,21), Time.local(2005,3,1,15,15,10).last_week
+ assert_equal Time.local(2005,2,22), Time.local(2005,3,1,15,15,10).last_week(:tuesday)
+ assert_equal Time.local(2005,2,25), Time.local(2005,3,1,15,15,10).last_week(:friday)
+ assert_equal Time.local(2006,10,30), Time.local(2006,11,6,0,0,0).last_week
+ assert_equal Time.local(2006,11,15), Time.local(2006,11,23,0,0,0).last_week(:wednesday)
+ end
+ end
def test_next_week
with_env_tz 'US/Eastern' do
@@ -662,6 +676,10 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal Time.local(2004, 2, 29), Time.local(2004, 3, 31).prev_month
end
+ def test_last_month_on_31st
+ assert_equal Time.local(2004, 2, 29), Time.local(2004, 3, 31).last_month
+ end
+
def test_xmlschema_is_available
assert_nothing_raised { Time.now.xmlschema }
end