aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-03-17 02:54:23 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-03-17 02:54:23 +0000
commit895487c1224bf85047f317e7bddf4f2abdea0822 (patch)
treeab133363378ef844d4dd60e31d3fba3e170ed757 /activesupport
parent77ee522bf6c97352485fad3b72866f7ab424ecaf (diff)
downloadrails-895487c1224bf85047f317e7bddf4f2abdea0822.tar.gz
rails-895487c1224bf85047f317e7bddf4f2abdea0822.tar.bz2
rails-895487c1224bf85047f317e7bddf4f2abdea0822.zip
TimeWithZone responds to Ruby 1.9 weekday-named query methods
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9041 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb6
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb7
3 files changed, 15 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index d72fdadf3f..6b1130a32a 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* TimeWithZone responds to Ruby 1.9 weekday-named query methods [Geoff Buesing]
+
* TimeWithZone caches TZInfo::TimezonePeriod used for time conversion so that it can be reused, and enforces DST rules correctly when instance is created from a local time [Geoff Buesing]
* Fixed that BufferedLogger should create its own directory if one doesn't already exist #11285 [lotswholetime]
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 68585e8273..10c3543d6e 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -153,6 +153,12 @@ module ActiveSupport
alias_method :mday, :day
alias_method :month, :mon
+ %w(sunday? monday? tuesday? wednesday? thursday? friday? saturday?).each do |name|
+ define_method(name) do
+ time.__send__(name)
+ end
+ end unless RUBY_VERSION < '1.9'
+
def to_a
time.to_a[0, 8].push(dst?, zone)
end
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 5f1a002071..e828e62f9b 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -281,6 +281,13 @@ uses_tzinfo 'TimeWithZoneTest' do
assert_equal true, twz.dst?
assert_equal 'EDT', twz.zone
end
+
+ def test_ruby_19_weekday_name_query_methods
+ ruby_19_or_greater = RUBY_VERSION >= '1.9'
+ %w(sunday? monday? tuesday? wednesday? thursday? friday? saturday?).each do |name|
+ assert_equal ruby_19_or_greater, @twz.respond_to?(name)
+ end
+ end
end
class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase