From 5bc63de8819448e7342f3cb0ac08af667ccc81e5 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 12 Jan 2023 10:04:49 +0100 Subject: QML: Add more overloads to Qt.format{Date|Time|DateTime}() Since JavaScript has no concept of time or date separate from the Date object that contains both, and since we implicitly (via QVariant::convert) or explicitly accept string arguments to all these methods, we should really accept string coercions of Date objects. We should also make all the string overloads explicit. Converting strings to QDateTime is a really obscure feature of the metatype system. We should not rely on it. Furthermore, we need to accept QDateTime, as the native representation of the JavaScript Date object, as argument to formatDate() and formatTime(). Otherwise there are two ambiguous paths to calling formatTime() or formatDate() using a Date object: Either coerce the Date into a string and call the string overload or coerce it into a QTime or QDate and call the QTime or QDate overload. The QML engine special cases this and prefers the QTime/QDate way, but this just needlessly complicates the overload resolution. Interestingly, tst_qqmlqt already tests most of those variants. We just have to add the JS string coercions. Task-number: QTBUG-109380 Change-Id: I880e622256fe115dade32bde880605df2031ff2f Reviewed-by: Fabian Kosmale Reviewed-by: Sami Shalayel --- src/qml/jsruntime/qv4dateobject_p.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/qml/jsruntime/qv4dateobject_p.h') diff --git a/src/qml/jsruntime/qv4dateobject_p.h b/src/qml/jsruntime/qv4dateobject_p.h index 147638744d..ad5b51f063 100644 --- a/src/qml/jsruntime/qv4dateobject_p.h +++ b/src/qml/jsruntime/qv4dateobject_p.h @@ -207,6 +207,7 @@ struct DateObject: ReferenceObject { static QString dateTimeToString(const QDateTime &dateTime, ExecutionEngine *engine); static QDate dateTimeToDate(const QDateTime &dateTime); + static QDateTime stringToDateTime(const QString &string, ExecutionEngine *engine); }; template<> -- cgit v1.2.3