Allow 24:00:00 for ISO dates in QDateTime::fromString().
ISO 8601 section 4.2.3 states that "The end of one calendar day [24:00] coincides with [00:00] at the start of the next calendar day", so fromString() was updated to account for this. Task-number: QTBUG-25387 Change-Id: I391db0da755dbc822ba0820c302a2c10391e1f3b Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
1668c47608
commit
d8e457323c
@ -3206,7 +3206,7 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f)
|
||||
case Qt::ISODate: {
|
||||
QString tmp = s;
|
||||
Qt::TimeSpec ts = Qt::LocalTime;
|
||||
const QDate date = QDate::fromString(tmp.left(10), Qt::ISODate);
|
||||
QDate date = QDate::fromString(tmp.left(10), Qt::ISODate);
|
||||
if (tmp.size() == 10)
|
||||
return QDateTime(date);
|
||||
|
||||
@ -3240,7 +3240,15 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f)
|
||||
return dt;
|
||||
}
|
||||
}
|
||||
return QDateTime(date, QTime::fromString(tmp, Qt::ISODate), ts);
|
||||
|
||||
QTime time(QTime::fromString(tmp, Qt::ISODate));
|
||||
if (!time.isValid() && tmp == QString::fromLatin1("24:00:00")) {
|
||||
// ISO 8601 (section 4.2.3) says that 24:00 is equivalent to 00:00 the next day.
|
||||
date = date.addDays(1);
|
||||
// Don't need to correct time since QDateTime constructor will do it for us.
|
||||
}
|
||||
|
||||
return QDateTime(date, time, ts);
|
||||
}
|
||||
case Qt::SystemLocaleDate:
|
||||
case Qt::SystemLocaleShortDate:
|
||||
|
@ -1268,6 +1268,22 @@ void tst_QDateTime::fromStringTextDate_data()
|
||||
<< 28 << 6 << 2005 << 7 << 57 << 30 << 110
|
||||
<< int(Qt::LocalTime);
|
||||
|
||||
// Should be next day according to ISO 8601 section 4.2.3.
|
||||
QTest::newRow("ISO date 24:00") << QString("2012-06-04T24:00:00")
|
||||
<< int(Qt::ISODate)
|
||||
<< 5 << 6 << 2012 << 0 << 0 << 0 << 0
|
||||
<< int(Qt::LocalTime);
|
||||
|
||||
QTest::newRow("ISO date 24:00 end of month") << QString("2012-06-30T24:00:00")
|
||||
<< int(Qt::ISODate)
|
||||
<< 1 << 7 << 2012 << 0 << 0 << 0 << 0
|
||||
<< int(Qt::LocalTime);
|
||||
|
||||
QTest::newRow("ISO date 24:00 end of month and year") << QString("2012-12-31T24:00:00")
|
||||
<< int(Qt::ISODate)
|
||||
<< 1 << 1 << 2013 << 0 << 0 << 0 << 0
|
||||
<< int(Qt::LocalTime);
|
||||
|
||||
QTest::newRow("Year 0999") << QString("Tue Jun 17 08:00:10 0999")
|
||||
<< int(Qt::TextDate)
|
||||
<< 17 << 6 << 999 << 8 << 0 << 10 << 0
|
||||
|
Loading…
Reference in New Issue
Block a user