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

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.14
    • Core: Date/Time
    • None
    • 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

        Issue Links

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

          Activity

            People

              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

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes