summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/time/qdatetimeparser/tst_qdatetimeparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/time/qdatetimeparser/tst_qdatetimeparser.cpp')
-rw-r--r--tests/auto/corelib/time/qdatetimeparser/tst_qdatetimeparser.cpp91
1 files changed, 63 insertions, 28 deletions
diff --git a/tests/auto/corelib/time/qdatetimeparser/tst_qdatetimeparser.cpp b/tests/auto/corelib/time/qdatetimeparser/tst_qdatetimeparser.cpp
index 98dd36bc32..bfc811eebe 100644
--- a/tests/auto/corelib/time/qdatetimeparser/tst_qdatetimeparser.cpp
+++ b/tests/auto/corelib/time/qdatetimeparser/tst_qdatetimeparser.cpp
@@ -1,34 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <private/qdatetimeparser_p.h>
+using namespace Qt::StringLiterals;
+
QT_BEGIN_NAMESPACE
// access to needed members in QDateTimeParser
@@ -71,6 +48,7 @@ class tst_QDateTimeParser : public QObject
Q_OBJECT
private Q_SLOTS:
+ void reparse();
void parseSection_data();
void parseSection();
@@ -78,6 +56,61 @@ private Q_SLOTS:
void intermediateYear();
};
+void tst_QDateTimeParser::reparse()
+{
+ const QDateTime when = QDate(2023, 6, 15).startOfDay();
+ // QTBUG-114575: 6.2 through 6.5 got back a bogus Qt::TimeZone (with zero offset):
+ const auto expect = ([](QStringView name) {
+ // When local time is UTC or a fixed offset from it, the parser prefers
+ // to interpret a UTC or offset suffix as such, rather than as local
+ // time (thereby avoiding DST-ness checks). We have to match that here.
+ if (name == "UTC"_L1)
+ return Qt::UTC;
+ if (name.startsWith(u'+') || name.startsWith(u'-')) {
+ if (std::all_of(name.begin() + 1, name.end(), [](QChar ch) { return ch == u'0'; }))
+ return Qt::UTC;
+ if (std::all_of(name.begin() + 1, name.end(), [](QChar ch) { return ch.isDigit(); }))
+ return Qt::OffsetFromUTC;
+ // Potential hh:mm offset ? Not yet seen as local tzname[] entry.
+ }
+ return Qt::LocalTime;
+ });
+
+ const QStringView format = u"dd/MM/yyyy HH:mm t";
+ QDateTimeParser who(QMetaType::QDateTime, QDateTimeParser::DateTimeEdit);
+ QVERIFY(who.parseFormat(format));
+ {
+ // QDTP defaults to the system locale.
+ const auto state = who.parse(QLocale::system().toString(when, format), -1, when, false);
+ QCOMPARE(state.state, QDateTimeParser::Acceptable);
+ QVERIFY(!state.conflicts);
+ QCOMPARE(state.padded, 0);
+ QCOMPARE(state.value.timeSpec(), expect(when.timeZoneAbbreviation()));
+ QCOMPARE(state.value, when);
+ }
+ {
+ // QDT::toString() uses the C locale:
+ who.setDefaultLocale(QLocale::c());
+ const QString zoneName = ([when]() {
+#if QT_CONFIG(timezone)
+ if (QLocale::c() != QLocale::system()) {
+ const QString local = when.timeRepresentation().displayName(
+ when, QTimeZone::ShortName, QLocale::c());
+ if (!local.isEmpty())
+ return local;
+ }
+#endif
+ return when.timeZoneAbbreviation();
+ })();
+ const auto state = who.parse(when.toString(format), -1, when, false);
+ QCOMPARE(state.state, QDateTimeParser::Acceptable);
+ QVERIFY(!state.conflicts);
+ QCOMPARE(state.padded, 0);
+ QCOMPARE(state.value.timeSpec(), expect(zoneName));
+ QCOMPARE(state.value, when);
+ }
+}
+
void tst_QDateTimeParser::parseSection_data()
{
QTest::addColumn<QString>("format");
@@ -165,10 +198,12 @@ void tst_QDateTimeParser::intermediateYear()
QVERIFY(testParser.parseFormat(format));
+ // Indian/Cocos has a transition at the start of 1900, so it started this
+ // day at 00:02:20, throwing a time offset into QDTP.
QDateTime val(QDate(1900, 1, 1).startOfDay());
const QDateTimeParser::StateNode tmp = testParser.parse(input, -1, val, false);
QCOMPARE(tmp.state, QDateTimeParser::Intermediate);
- QCOMPARE(tmp.value, expected.startOfDay());
+ QCOMPARE(tmp.value.date(), expected);
}
QTEST_APPLESS_MAIN(tst_QDateTimeParser)