diff --git a/lib/time.rb b/lib/time.rb index 679cc82..a6b8f6b 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -482,7 +482,9 @@ def strptime(date, format, now=self.now) yday = d[:yday] if (d[:cwyear] && !year) || ((d[:cwday] || d[:cweek]) && !(d[:mon] && d[:mday])) # make_time doesn't deal with cwyear/cwday/cweek - return Date.strptime(date, format).to_time + d2 = Date.strptime(date, format) + year = d2.year + yday = d2.yday end if (d[:wnum0] || d[:wnum1]) && !yday && !(d[:mon] && d[:mday]) yday = Date.strptime(date, format).yday diff --git a/test/test_time.rb b/test/test_time.rb index 4054bc4..2ed8be9 100644 --- a/test/test_time.rb +++ b/test/test_time.rb @@ -587,6 +587,14 @@ def test_strptime_wuvg assert_equal(Time.local(2015, 12, 28), Time.strptime("53 15", "%V %g")) end + def test_strptime_wuvg_with_time + assert_equal(Time.local(2019, 1, 1, 10, 30, 15), Time.strptime("2019-W01-2 10:30:15", "%G-W%V-%u %H:%M:%S")) + assert_equal(Time.local(2019, 2, 7, 12, 34), Time.strptime("4 5 2019 12:34", "%u %U %Y %H:%M")) + t = Time.strptime("2004-W53-7 12:00:00.5 +0900", "%G-W%V-%u %H:%M:%S.%N %z") + assert_equal(Time.new(2005, 1, 2, 12, 0, 1/2r, "+09:00"), t) + assert_equal(9 * 3600, t.utc_offset) + end + def test_nsec assert_equal(123456789, Time.parse("2000-01-01T00:00:00.123456789+00:00").tv_nsec) end