From a56b150b6401cc3384d2be2db7530662047966e0 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Tue, 23 Apr 2013 12:48:31 +0100 Subject: Adjust for daylight savings in String#to_time The changes in b79adc4323 had a bug where if the time in the String was in standard time but the current time was in daylight savings then the calculated adjustment was off by an hour. This commit fixes this and adds extra tests for the following: * time in string is standard time, current time is standard time * time in string is standard time, current time is daylight savings * time in string is daylight savings, current time is standard time * time in string is daylight savings, current time is daylight savings Fixes #10306. --- .../lib/active_support/core_ext/string/conversions.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/string') diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 428fa1f826..d2a2db32bb 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -20,19 +20,17 @@ class String return if parts.empty? now = Time.now - offset = parts[:offset] - utc_offset = form == :utc ? 0 : now.utc_offset - adjustment = offset ? offset - utc_offset : 0 - - Time.send( - form, + time = Time.new( parts.fetch(:year, now.year), parts.fetch(:mon, now.month), parts.fetch(:mday, now.day), parts.fetch(:hour, 0), parts.fetch(:min, 0), - parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0) - ) - adjustment + parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0), + parts.fetch(:offset, form == :utc ? 0 : nil) + ) + + form == :utc ? time.utc : time.getlocal end # Converts a string to a Date value. -- cgit v1.2.3