Project

General

Profile

Bug #14241 ยป time-strptime-wnum-cw-14241.patch

jeremyevans0 (Jeremy Evans), 08/11/2019 07:31 PM

View differences:

lib/time.rb
397 397
    # %D :: Date (%m/%d/%y)
398 398
    # %e :: Day of the month, blank-padded ( 1..31)
399 399
    # %F :: Equivalent to %Y-%m-%d (the ISO 8601 date format)
400
    # %g :: The last two digits of the commercial year
401
    # %G :: The week-based year according to ISO-8601 (week 1 starts on Monday
402
    #       and includes January 4)
400 403
    # %h :: Equivalent to %b
401 404
    # %H :: Hour of the day, 24-hour clock (00..23)
402 405
    # %I :: Hour of the day, 12-hour clock (01..12)
......
457 460
      else
458 461
        year = d[:year]
459 462
        year = yield(year) if year && block_given?
460
        t = make_time(date, year, d[:yday], d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
463
        yday = d[:yday]
464
        if (d[:cwyear] && !year) || ((d[:cwday] || d[:cweek]) && !(d[:mon] && d[:mday]))
465
          # make_time doesn't deal with cwyear/cwday/cweek
466
          return Date.strptime(date, format).to_time
467
        end
468
        if (d[:wnum0] || d[:wnum1]) && !yday && !(d[:mon] && d[:mday])
469
          yday = Date.strptime(date, format).yday
470
        end
471
        t = make_time(date, year, yday, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
461 472
      end
462 473
      t
463 474
    end
test/test_time.rb
528 528
    assert_equal(15, t.hour)
529 529
  end
530 530

  
531
  def test_strptime_wuvg
532
    assert_equal(Time.local(2019, 1, 30), Time.strptime("3 4 2019", "%w %W %Y"))
533
    assert_equal(Time.local(2019, 2, 7), Time.strptime("4 5 2019", "%u %U %Y"))
534
    assert_equal(Time.local(2019, 1, 28), Time.strptime("4 2019", "%W %Y"))
535
    assert_equal(Time.local(2019, 2, 3), Time.strptime("5 2019", "%U %Y"))
536
    assert_equal(Time.local(2019, 1, 1), Time.strptime("1 2 2019", "%V %w %G"))
537
    assert_equal(Time.local(2016, 1, 1), Time.strptime("53 5 15", "%V %w %g"))
538
    assert_equal(Time.local(2018, 12, 31), Time.strptime("1 2019", "%V %G"))
539
    assert_equal(Time.local(2015, 12, 28), Time.strptime("53 15", "%V %g"))
540
  end
541

  
531 542
  def test_nsec
532 543
    assert_equal(123456789, Time.parse("2000-01-01T00:00:00.123456789+00:00").tv_nsec)
533 544
  end
534
-