aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2014-05-11 16:00:55 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2014-05-11 16:00:55 +0100
commit7dce1e6d98f78d0cce963456f226811c22bb645d (patch)
treed613c225849da4bf91ee87c30d17815fc6e89eb5 /activesupport
parent0e909cd3078bab352eb741426024334afe0d6820 (diff)
downloadrails-7dce1e6d98f78d0cce963456f226811c22bb645d.tar.gz
rails-7dce1e6d98f78d0cce963456f226811c22bb645d.tar.bz2
rails-7dce1e6d98f78d0cce963456f226811c22bb645d.zip
Tidy up implementation of #15010
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb8
-rw-r--r--activesupport/test/time_zone_test.rb10
2 files changed, 7 insertions, 11 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 4c4c055252..72efb09fbe 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -291,16 +291,10 @@ module ActiveSupport
parts = Date._parse(str, false)
return if parts.empty?
- default_mday = if parts[:year] || parts[:mon]
- 1
- else
- now.day
- end
-
time = Time.new(
parts.fetch(:year, now.year),
parts.fetch(:mon, now.month),
- parts.fetch(:mday, default_mday),
+ parts.fetch(:mday, parts[:year] || parts[:mon] ? 1 : now.day),
parts.fetch(:hour, 0),
parts.fetch(:min, 0),
parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0),
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index 37276b71e1..127bcc2b4d 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -255,10 +255,12 @@ class TimeZoneTest < ActiveSupport::TestCase
end
def test_parse_with_day_omitted
- zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
- zone.stubs(:now).returns zone.local(1999, 12, 31)
- twz = zone.parse('Feb')
- assert_equal Time.utc(1999, 2, 1), twz.time
+ with_env_tz 'US/Eastern' do
+ zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
+ assert_equal Time.local(2000, 2, 1), zone.parse('Feb', Time.local(2000, 1, 1))
+ assert_equal Time.local(2005, 2, 1), zone.parse('Feb 2005', Time.local(2000, 1, 1))
+ assert_equal Time.local(2005, 2, 2), zone.parse('2 Feb 2005', Time.local(2000, 1, 1))
+ end
end
def test_parse_should_not_black_out_system_timezone_dst_jump