Changeset 8884
- Timestamp:
- 02/16/08 23:15:59 (5 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/time_with_zone.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/time_with_zone_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r8878 r8884 1 1 *SVN* 2 3 * 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] 2 4 3 5 * Add String#squish and String#squish! to remove consecutive chunks of whitespace. #11123 [jordi, Henrik N] trunk/activesupport/lib/active_support/time_with_zone.rb
r8854 r8884 130 130 end 131 131 132 # Need to override #- to intercept situation where a Time or Time With Zone object is passed in 132 # If wrapped #time is a DateTime, use DateTime#since instead of #+ 133 # Otherwise, just pass on to #method_missing 134 def +(other) 135 time.acts_like?(:date) ? method_missing(:since, other) : method_missing(:+, other) 136 end 137 138 # If a time-like object is passed in, compare it with #utc 139 # Else if wrapped #time is a DateTime, use DateTime#ago instead of #- 133 140 # Otherwise, just pass on to method missing 134 141 def -(other) 135 other.acts_like?(:time) ? utc - other : method_missing(:-, other) 142 if other.acts_like?(:time) 143 utc - other 144 else 145 time.acts_like?(:date) ? method_missing(:ago, other) : method_missing(:-, other) 146 end 136 147 end 137 148 … … 177 188 # Ensure proxy class responds to all methods that underlying time instance responds to 178 189 def respond_to?(sym) 190 # consistently respond false to acts_like?(:date), regardless of whether #time is a Time or DateTime 191 return false if sym.to_s == 'acts_like_date?' 179 192 super || time.respond_to?(sym) 180 193 end trunk/activesupport/test/core_ext/time_with_zone_test.rb
r8854 r8884 122 122 end 123 123 124 def test_plus 124 def test_plus_with_integer 125 125 assert_equal Time.utc(1999, 12, 31, 19, 0 ,5), (@twz + 5).time 126 end 127 128 def test_plus_with_integer_when_self_wraps_datetime 129 datetime = DateTime.civil(2000, 1, 1, 0) 130 twz = ActiveSupport::TimeWithZone.new(datetime, @time_zone) 131 assert_equal DateTime.civil(1999, 12, 31, 19, 0 ,5), (twz + 5).time 126 132 end 127 133 … … 130 136 end 131 137 132 def test_minus 138 def test_minus_with_integer 133 139 assert_equal Time.utc(1999, 12, 31, 18, 59 ,55), (@twz - 5).time 140 end 141 142 def test_minus_with_integer_when_self_wraps_datetime 143 datetime = DateTime.civil(2000, 1, 1, 0) 144 twz = ActiveSupport::TimeWithZone.new(datetime, @time_zone) 145 assert_equal DateTime.civil(1999, 12, 31, 18, 59 ,55), (twz - 5).time 134 146 end 135 147 … … 175 187 def test_acts_like_time 176 188 assert @twz.acts_like?(:time) 189 assert ActiveSupport::TimeWithZone.new(DateTime.civil(2000), @time_zone).acts_like?(:time) 190 end 191 192 def test_acts_like_date 193 assert_equal false, @twz.acts_like?(:date) 194 assert_equal false, ActiveSupport::TimeWithZone.new(DateTime.civil(2000), @time_zone).acts_like?(:date) 177 195 end 178 196