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
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-84334 QDate::fromString cannot parse date with negative year
-
- Closed
-