diff --git a/autotests/eventhandlertest.cpp b/autotests/eventhandlertest.cpp index b288b4a54..de191d7f4 100644 --- a/autotests/eventhandlertest.cpp +++ b/autotests/eventhandlertest.cpp @@ -163,6 +163,7 @@ void EventHandlerTest::timeString() QLocale().toString(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().time(), QLocale::LongFormat)); QCOMPARE(eventHandler.getTimeString(true, QLocale::LongFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)), format.formatRelativeDate(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().date(), QLocale::LongFormat)); + QCOMPARE(eventHandler.getTimeString(QStringLiteral("hh:mm")), QDateTime::fromMSecsSinceEpoch(1432735824654, Qt::UTC).toString(QStringLiteral("hh:mm"))); } void EventHandlerTest::nullTimeString() diff --git a/src/eventhandler.cpp b/src/eventhandler.cpp index 6b4b65a38..4d062994a 100644 --- a/src/eventhandler.cpp +++ b/src/eventhandler.cpp @@ -143,6 +143,11 @@ QString EventHandler::getTimeString(bool relative, QLocale::FormatType format, b return {}; } +QString EventHandler::getTimeString(const QString &format, bool isPending, const QDateTime &lastUpdated) +{ + return getTime(isPending, lastUpdated).toLocalTime().toString(format); +} + bool EventHandler::isHighlighted() { if (m_room == nullptr) { diff --git a/src/eventhandler.h b/src/eventhandler.h index 673710239..277273c9e 100644 --- a/src/eventhandler.h +++ b/src/eventhandler.h @@ -98,6 +98,8 @@ public: */ QString getTimeString(bool relative, QLocale::FormatType format = QLocale::ShortFormat, bool isPending = false, QDateTime lastUpdated = {}) const; + QString getTimeString(const QString &format, bool isPending = false, const QDateTime &lastUpdated = {}); + /** * @brief Whether the event should be highlighted in the timeline. * diff --git a/src/models/messagecontentmodel.cpp b/src/models/messagecontentmodel.cpp index 4b7c15ef1..67e9b1f83 100644 --- a/src/models/messagecontentmodel.cpp +++ b/src/models/messagecontentmodel.cpp @@ -258,7 +258,7 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const }); auto lastUpdated = pendingIt == m_room->pendingEvents().cend() ? QDateTime() : pendingIt->lastUpdated(); - return eventHandler.getTimeString(false, QLocale::ShortFormat, m_isPending, lastUpdated); + return eventHandler.getTimeString(QStringLiteral("hh:mm"), m_isPending, lastUpdated); } if (role == AuthorRole) { return QVariant::fromValue(m_eventSenderObject.get());