Only take the date parts from Time.zone.now

When there are missing components in the Hash returned by
Date._parse only the date components should default to the
value of Time.zone.now, the time components should all
default to zero.
This commit is contained in:
Andrew White 2012-12-01 20:43:07 +00:00
parent 583cc11dd7
commit c89b6c4cdc
2 changed files with 10 additions and 3 deletions

@ -285,9 +285,9 @@ def parse(str, now=now)
parts.fetch(:year, now.year),
parts.fetch(:mon, now.month),
parts.fetch(:mday, now.day),
parts.fetch(:hour, now.hour),
parts.fetch(:min, now.min),
parts.fetch(:sec, now.sec) + parts.fetch(:sec_fraction, 0),
parts.fetch(:hour, 0),
parts.fetch(:min, 0),
parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0),
parts.fetch(:offset, 0)
)

@ -219,6 +219,13 @@ def test_parse_should_black_out_app_timezone_dst_jump
end
end
def test_parse_with_missing_time_components
zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
zone.stubs(:now).returns zone.local(1999, 12, 31, 12, 59, 59)
twz = zone.parse('2012-12-01')
assert_equal Time.utc(2012, 12, 1), twz.time
end
def test_parse_with_javascript_date
zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
twz = zone.parse("Mon May 28 2012 00:00:00 GMT-0700 (PDT)")