Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.14
-
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
- duplicates
-
QTBUG-74323 QDate::from string gives wrong year
- Closed
- is duplicated by
-
QTBUG-89147 QDate::fromString() still asumes we're in the 20th century
- Closed
- relates to
-
QTBUG-117055 Implement a generic internal framework for formats for parsing and serializing
- Open
-
QTBUG-77948 Rewrite QDateTimeParser
- Open
-
QTBUG-84334 QDate::fromString cannot parse date with negative year
- Closed
-
QTBUG-46843 Way to change base year for QDate::fromString 2 digit year parsing
- Closed