diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index af853f5f15c18431e8b4248e3669862705433329..78b6c47d300c634fa0197c308016103ddbd28deb 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Adding TimeWithZone#between? [Geoff Buesing] + * Time.=== returns true for TimeWithZone instances [Geoff Buesing] * TimeWithZone #+ and #- behave consistently with numeric arguments regardless of whether wrapped time is a Time or DateTime; consistenty answers false to #acts_like?(:date) [Geoff Buesing] diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 377eee949f42954ca3e1d089af31256e4cd9a454..cd4ea8c532c638a5783e74cbc96037794eec35e1 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -125,6 +125,10 @@ def <=>(other) utc <=> other end + def between?(min, max) + utc.between?(min, max) + end + def eql?(other) utc == other end @@ -160,7 +164,7 @@ def to_i alias_method :hash, :to_i alias_method :tv_sec, :to_i - # A TimeProxy acts like a Time, so just return self + # A TimeWithZone acts like a Time, so just return self def to_time self end diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 3421b85e60937cda8e381f11047bf7c819e24069..c93d6157e716f327d78ccba50f4eadd0c70d0b83 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -116,6 +116,11 @@ def test_compare_with_time_with_zone assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) end + def test_between? + assert @twz.between?(Time.utc(1999,12,31,23,59,59), Time.utc(2000,1,1,0,0,1)) + assert_equal false, @twz.between?(Time.utc(2000,1,1,0,0,1), Time.utc(2000,1,1,0,0,2)) + end + def test_eql? assert @twz.eql?(Time.utc(2000)) assert @twz.eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone["Hawaii"]) )