Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-82886

Qt::DefaultLocaleShortDate / QLocale::ShortFormat date parsing doesn't deal with 4-digit years

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 5.14
    • Core: Date/Time
    • None
    • 21

      QDate::fromString(QLatin1String("2/3/2020"), Qt::DefaultLocaleShortDate) doesn't work. QDate::fromString(QLatin1String("2/3/20"), Qt::DefaultLocaleShortDate) parses the date as Feb 3, 1920 in an American locale. Yet QLocale().dateFormat(QLocale::ShortFormat) recommends "M/d/yy" as the format to use. The idea of using 2-digit years at all was obsolete more than 20 years ago.

      In Qt 6 we should always use 4-digit years for reading and writing short-format dates.

      If we must support 2-digit years for some reason, we could use a sliding window somehow so that 99 means 1999 and 20 means 2020, but that's a slippery slope to extended bikeshedding about where the boundary should be.

      $ ./dateparse 02/03/99
      [     0.000 D] default unknown - acceptable short format "M/d/yy"
      [     0.000 D] default unknown - parsed "02/03/99" as "Wed Feb 3 1999"
      [     0.000 D] default unknown - parsed 2/3/2020 as ""
      [     0.000 D] default unknown - parsed 2/3/20 as "Tue Feb 3 1920"
      

        1. dateparse.tgz
          1 kB
          Shawn Rutledge
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Eddy Edward Welbourne
            srutledg Shawn Rutledge
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes