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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.14
    • Fix Version/s: None
    • Component/s: Core: Date/Time
    • Labels:
      None
    • Story Points:
      21

      Description

      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"
      

        Attachments

        1. dateparse.tgz
          1 kB
          Shawn Rutledge

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              Eddy Edward Welbourne
              Reporter:
              srutledg Shawn Rutledge
              PM Owner:
              Vladimir Minenko Vladimir Minenko
              RnD Owner:
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes