aboutsummaryrefslogtreecommitdiff
path: root/lib/converters.h
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-11-11 22:18:18 +0100
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-11-12 16:22:52 +0100
commitf2bf3f203965c51824e8681427798f7a09784ce3 (patch)
treeb2ce266ceb0cbbf35d10f5f0ecd548e0e59ad42e /lib/converters.h
parent05e71a72fdc6da3fb319edc67b723999285c9657 (diff)
downloadlibquotient-f2bf3f203965c51824e8681427798f7a09784ce3.tar.gz
libquotient-f2bf3f203965c51824e8681427798f7a09784ce3.zip
Make ReceiptEvent constructible from content
Makes the Room::P::toJson() code more readable.
Diffstat (limited to 'lib/converters.h')
-rw-r--r--lib/converters.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/converters.h b/lib/converters.h
index 2df18b03..d9a68bfb 100644
--- a/lib/converters.h
+++ b/lib/converters.h
@@ -134,7 +134,10 @@ struct JsonConverter<QString> : public TrivialJsonDumper<QString> {
template <>
struct JsonConverter<QDateTime> {
- static auto dump(const QDateTime& val) = delete; // not provided yet
+ static auto dump(const QDateTime& val)
+ {
+ return val.isValid() ? val.toMSecsSinceEpoch() : QJsonValue();
+ }
static auto load(const QJsonValue& jv)
{
return QDateTime::fromMSecsSinceEpoch(fromJson<qint64>(jv), Qt::UTC);
@@ -143,7 +146,7 @@ struct JsonConverter<QDateTime> {
template <>
struct JsonConverter<QDate> {
- static auto dump(const QDate& val) = delete; // not provided yet
+ static auto dump(const QDate& val) { return toJson(QDateTime(val)); }
static auto load(const QJsonValue& jv)
{
return fromJson<QDateTime>(jv).date();