Permalink
Browse files

Tidy up implementation of #15010

  • Loading branch information...
1 parent 0e909cd commit 7dce1e6d98f78d0cce963456f226811c22bb645d @pixeltrix pixeltrix committed May 11, 2014
Showing with 7 additions and 11 deletions.
  1. +1 −7 activesupport/lib/active_support/values/time_zone.rb
  2. +6 −4 activesupport/test/time_zone_test.rb
@@ -291,16 +291,10 @@ def parse(str, now=now())
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),
@@ -255,10 +255,12 @@ def test_parse_with_incomplete_date
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

0 comments on commit 7dce1e6

Please sign in to comment.