From dff02466a01caad885b6bd0759cf482342332306 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 9 Dec 2021 16:30:03 +0100 Subject: Use qtbase's new (private) QLocalTime for Date's UTC offsets This puts all use of system time_t functions in one place, instead of spreading it out. Its implementation improves on what was formerly done in V4 Date's offset calculations, while simplifying them and eliminating most of the #if-ery. Add four more test-cases to tst_qqmlqt::dateTimeConversion(), based on issues seen on MinGW, getting the time-zone wrong due to the failure of localtime_r(); MinGW can use localtime_s, as QLocalTime now does. Revised tst_qqmllocale::timeZoneUpdated()'s conditions. The QEXPECT_FAIL()s have stopped triggering, at least on Darwin, and the issue isn't that Date.timeZoneUpdated() wasn't working, it's that (now only on Android and Windows) we don't have a way to set the system time-zone referenced by the system functions that QLocalTime calls to get time-zone offsets. Setting the TZ environment variable only works on faithful POSIX implementations. Pick-to: 6.4 Fixes: QTBUG-85149 Fixes: QTBUG-95993 Fixes: QTBUG-102971 Change-Id: I7bc983b9fd7167e3bab3db41dbc1c6f4a78665b9 Reviewed-by: Ulf Hermann --- tests/auto/qml/qqmlqt/data/dateTimeConversion.qml | 5 +++++ tests/auto/qml/qqmlqt/tst_qqmlqt.cpp | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'tests/auto/qml/qqmlqt') diff --git a/tests/auto/qml/qqmlqt/data/dateTimeConversion.qml b/tests/auto/qml/qqmlqt/data/dateTimeConversion.qml index 300074dec1..7e0d194b3a 100644 --- a/tests/auto/qml/qqmlqt/data/dateTimeConversion.qml +++ b/tests/auto/qml/qqmlqt/data/dateTimeConversion.qml @@ -6,6 +6,11 @@ QtObject { property variant qdate: new Date(2008,11,24) // 2008/12/24 hh:mm:ss.zzz property variant qdatetime: new Date(2008,11,24,14,15,38,200) // 2008/12/24 14:15:38.200 + property variant qdatetime0: new Date(2021, 6) // 2021-07-01 00:00:00 + property variant qdatetime0utc: new Date(Date.UTC(2021, 6)) // 2021-07-01 00:00:00 UTC + property variant qdatetime1: new Date(2021, 7, 0) // 2021-07-31 00:00:00 + property variant qdatetime1utc: new Date(Date.UTC(2021, 7, 0)) // 2021-07-31 00:00:00 UTC + property variant qdatetime2: new Date(2852,11,31,23,59,59,500) // 2852/12/31 23:59:59.500 property variant qdatetime3: new Date(2000,0,1,0,0,0,0) // 2000/01/01 00:00:00.000 property variant qdatetime4: new Date(2001,1,2) // 2001/02/02 hh:mm:ss.zzz diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp index 60a4c808c7..e0ad9bcd57 100644 --- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp +++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -766,8 +766,10 @@ void tst_qqmlqt::dateTimeConversion() QDate date(2008,12,24); QTime time(14,15,38,200); QDateTime dateTime(date, time); - //Note that when converting Date to QDateTime they can argue over historical DST data when converting to local time. - //Tests should use UTC or recent dates. + QDateTime dateTime0(QDate(2021, 7, 1).startOfDay()); + QDateTime dateTime0utc(QDate(2021, 7, 1).startOfDay(Qt::UTC)); + QDateTime dateTime1(QDate(2021, 7, 31).startOfDay()); + QDateTime dateTime1utc(QDate(2021, 7, 31).startOfDay(Qt::UTC)); QDateTime dateTime2(QDate(2852,12,31), QTime(23,59,59,500)); QDateTime dateTime3(QDate(2000,1,1), QTime(0,0,0,0)); QDateTime dateTime4(QDate(2001,2,2), QTime(0,0,0,0)); @@ -785,6 +787,10 @@ void tst_qqmlqt::dateTimeConversion() QCOMPARE(obj->property("qdate").toDate(), date); QCOMPARE(obj->property("qtime").toTime(), time); QCOMPARE(obj->property("qdatetime").toDateTime(), dateTime); + QCOMPARE(obj->property("qdatetime0").toDateTime(), dateTime0); + QCOMPARE(obj->property("qdatetime0utc").toDateTime(), dateTime0utc); + QCOMPARE(obj->property("qdatetime1").toDateTime(), dateTime1); + QCOMPARE(obj->property("qdatetime1utc").toDateTime(), dateTime1utc); QCOMPARE(obj->property("qdatetime2").toDateTime(), dateTime2); QCOMPARE(obj->property("qdatetime3").toDateTime(), dateTime3); QCOMPARE(obj->property("qdatetime4").toDateTime(), dateTime4); -- cgit v1.2.3