diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-08-24 13:48:18 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-08-25 20:36:37 +0200 |
commit | 555125416eb1a12e15dddb57207ce7d87751a64b (patch) | |
tree | f51faf78fcc045c83af7599ccd382bea96e3d10a /src/qml/jsapi/qjsengine.h | |
parent | ede3389a3e152d7436bda6a53dd93e8847ab026e (diff) |
QmlCompiler: Allow coercing date values to numbers
This is the equivalent of JavaScript's valueOf().
Change-Id: If850519d6dbc7354b447acb6aad8ac04211d059d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'src/qml/jsapi/qjsengine.h')
-rw-r--r-- | src/qml/jsapi/qjsengine.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/qml/jsapi/qjsengine.h b/src/qml/jsapi/qjsengine.h index dbeecb45ae..0851bf39ca 100644 --- a/src/qml/jsapi/qjsengine.h +++ b/src/qml/jsapi/qjsengine.h @@ -223,6 +223,8 @@ public: return from.toLocalTime().time(); if constexpr (std::is_same_v<To, QString>) return convertDateTimeToString(from.toLocalTime()); + if constexpr (std::is_same_v<To, double>) + return convertDateTimeToNumber(from.toLocalTime()); } if constexpr (std::is_same_v<From, QDate>) { @@ -234,6 +236,8 @@ public: } if constexpr (std::is_same_v<To, QString>) return convertDateTimeToString(coerceValue<QDate, QDateTime>(from)); + if constexpr (std::is_same_v<To, double>) + return convertDateTimeToNumber(coerceValue<QDate, QDateTime>(from)); } if constexpr (std::is_same_v<From, QTime>) { @@ -246,6 +250,8 @@ public: return QDateTime(coerceValue<QTime, QDate>(from), from, QTimeZone::LocalTime); if constexpr (std::is_same_v<To, QString>) return convertDateTimeToString(coerceValue<QTime, QDateTime>(from)); + if constexpr (std::is_same_v<To, double>) + return convertDateTimeToNumber(coerceValue<QTime, QDateTime>(from)); } if constexpr (std::is_same_v<To, std::remove_const_t<std::remove_pointer_t<To>> const *>) { @@ -325,6 +331,7 @@ private: QString convertQObjectToString(QObject *object); QString convertDateTimeToString(const QDateTime &dateTime); + double convertDateTimeToNumber(const QDateTime &dateTime); static QDate convertDateTimeToDate(const QDateTime &dateTime); template<typename T> |