From fc72d6815ad6ed447f1aea2dd98579305ea1cca4 Mon Sep 17 00:00:00 2001 From: Josua Schmid Date: Wed, 19 Oct 2016 18:43:57 +0200 Subject: Fix copy_time_to: Copy nsec instead of usec `copy_time_to` is a helper function for date and time calculations. It's being used by `prev_week`, `next_week` and `prev_weekday` to keep the time fraction when jumping around between days. Previously the nanoseconds part was lost during the operation. This lead to problems in practice if you were using the `end_of_day` calculation. Resulting in the time fraction of `end_of_day` not being the same as next week's `end_of_day`. With this fix `copy_time_to` doesn't forget the `nsec` digits. --- activesupport/test/core_ext/date_and_time_behavior.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/date_and_time_behavior.rb b/activesupport/test/core_ext/date_and_time_behavior.rb index bf83ac602f..6cc9781e02 100644 --- a/activesupport/test/core_ext/date_and_time_behavior.rb +++ b/activesupport/test/core_ext/date_and_time_behavior.rb @@ -126,7 +126,9 @@ module DateAndTimeBehavior end def test_next_week_at_same_time - assert_equal date_time_init(2005,2,28,15,15,10), date_time_init(2005,2,22,15,15,10).next_week(:monday, same_time: true) + assert_equal date_time_init(2005,2,28,15,15,10), date_time_init(2005,2,22,15,15,10).next_week(:monday, same_time: true) + assert_equal date_time_init(2005,2,28,15,15,10,999999), date_time_init(2005,2,22,15,15,10,999999).next_week(:monday, same_time: true) + assert_equal date_time_init(2005,2,28,15,15,10,Rational(999999999, 1000)), date_time_init(2005,2,22,15,15,10,Rational(999999999, 1000)).next_week(:monday, same_time: true) assert_equal date_time_init(2005,3,4,15,15,10), date_time_init(2005,2,22,15,15,10).next_week(:friday, same_time: true) assert_equal date_time_init(2006,10,30,0,0,0), date_time_init(2006,10,23,0,0,0).next_week(:monday, same_time: true) assert_equal date_time_init(2006,11,1,0,0,0), date_time_init(2006,10,23,0,0,0).next_week(:wednesday, same_time: true) -- cgit v1.2.3