From bfbf03ecee063adc9999c0dec50f8177594fb28f Mon Sep 17 00:00:00 2001 From: gbuesing Date: Thu, 8 May 2008 23:40:25 -0500 Subject: [PATCH] ActionView::InstanceTag#default_time_from_options with hash args uses Time.current as default; respects hash settings when time falls in system local spring DST gap --- actionpack/CHANGELOG | 2 ++ .../lib/action_view/helpers/date_helper.rb | 7 +++--- actionpack/test/template/date_helper_test.rb | 23 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 438fa24c75311..baba4ae5ed65d 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* InstanceTag#default_time_from_options with hash args uses Time.current as default; respects hash settings when time falls in system local spring DST gap [Geoff Buesing] + * select_date defaults to Time.zone.today when config.time_zone is set [Geoff Buesing] * Fixed that TextHelper#text_field would corrypt when raw HTML was used as the value (mchenryc, Kevin Glowacz) [#80] diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 542ef3ef65464..8a9c8044aef41 100755 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -683,12 +683,13 @@ def default_time_from_options(default) default[:min] ||= default[:minute] default[:sec] ||= default[:second] + time = Time.current + [:year, :month, :day, :hour, :min, :sec].each do |key| - default[key] ||= Time.now.send(key) + default[key] ||= time.send(key) end - Time.mktime(default[:year], default[:month], default[:day], - default[:hour], default[:min], default[:sec]) + Time.utc(default[:year], default[:month], default[:day], default[:hour], default[:min], default[:sec]) end end end diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 905cf0ba3102d..ae83c7bf4730f 100755 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1708,4 +1708,27 @@ def test_datetime_select_with_html_options assert_dom_equal expected, datetime_select("post", "updated_at", {}, :class => 'selector') end + uses_mocha 'TestInstanceTagDefaultTimeFromOptions' do + def test_instance_tag_default_time_from_options_uses_time_current_as_default_when_hash_passed_as_arg + dummy_instance_tag = ActionView::Helpers::InstanceTag.new(1,2,3) + Time.expects(:current).returns Time.now + dummy_instance_tag.send!(:default_time_from_options, :hour => 2) + end + + def test_instance_tag_default_time_from_options_respects_hash_arg_settings_when_time_falls_in_system_local_dst_spring_gap + with_env_tz('US/Central') do + dummy_instance_tag = ActionView::Helpers::InstanceTag.new(1,2,3) + Time.stubs(:now).returns Time.local(2006, 4, 2, 1) + assert_equal 2, dummy_instance_tag.send!(:default_time_from_options, :hour => 2).hour + end + end + end + + protected + def with_env_tz(new_tz = 'US/Eastern') + old_tz, ENV['TZ'] = ENV['TZ'], new_tz + yield + ensure + old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') + end end