diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2020-09-30 11:09:45 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-10-07 15:57:56 +0200 |
commit | 51a16a686209452e99e281fc1d80170e87ff6fd2 (patch) | |
tree | 51c3fd57bd1adec916449d9b5848d1254e295171 | |
parent | 6404084b9c1eba20421ced02a123bec7b857f012 (diff) |
Use fromIsoTimeString() in QDateTime::fromString() also for TextDate
That way it'll be consistent with QTime()'s parsing of the time part.
Change-Id: I3f66e5686ba6e2ea4bbc2d5a9a29a177de2d9e69
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index ff4c57b1f8..da3fee5b81 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -4825,46 +4825,11 @@ QDateTime QDateTime::fromString(QStringView string, Qt::DateFormat format) if (!ok || !month || !day) return QDateTime(); - QDate date(year, month, day); + const QDate date(year, month, day); if (!date.isValid()) return QDateTime(); - // ### fixme, use QStringView::tokenize() when available - QList<QStringView> timeParts = parts.at(timePart).split(QLatin1Char(':')); - if (timeParts.count() < 2 || timeParts.count() > 3) - return QDateTime(); - - int hour = timeParts.at(0).toInt(&ok); - if (!ok) - return QDateTime(); - - int minute = timeParts.at(1).toInt(&ok); - if (!ok) - return QDateTime(); - - int second = 0; - int millisecond = 0; - if (timeParts.count() > 2) { - // ### fixme, use QStringView::tokenize() when available - const QList<QStringView> secondParts = timeParts.at(2).split(QLatin1Char('.')); - if (secondParts.size() > 2) { - return QDateTime(); - } - - second = secondParts.first().toInt(&ok); - if (!ok) { - return QDateTime(); - } - - if (secondParts.size() > 1) { - millisecond = secondParts.last().toInt(&ok); - if (!ok) { - return QDateTime(); - } - } - } - - QTime time(hour, minute, second, millisecond); + const QTime time = fromIsoTimeString(parts.at(timePart), format, nullptr); if (!time.isValid()) return QDateTime(); |