Show time without seconds in timeline

This commit is contained in:
Tobias Fella
2024-07-21 17:32:12 +02:00
parent b34525a4d8
commit 2df2e39d43
4 changed files with 9 additions and 1 deletions

View File

@@ -163,6 +163,7 @@ void EventHandlerTest::timeString()
QLocale().toString(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().time(), QLocale::LongFormat)); QLocale().toString(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().time(), QLocale::LongFormat));
QCOMPARE(eventHandler.getTimeString(true, QLocale::LongFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)), QCOMPARE(eventHandler.getTimeString(true, QLocale::LongFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)),
format.formatRelativeDate(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().date(), QLocale::LongFormat)); 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() void EventHandlerTest::nullTimeString()

View File

@@ -143,6 +143,11 @@ QString EventHandler::getTimeString(bool relative, QLocale::FormatType format, b
return {}; return {};
} }
QString EventHandler::getTimeString(const QString &format, bool isPending, const QDateTime &lastUpdated)
{
return getTime(isPending, lastUpdated).toLocalTime().toString(format);
}
bool EventHandler::isHighlighted() bool EventHandler::isHighlighted()
{ {
if (m_room == nullptr) { if (m_room == nullptr) {

View File

@@ -98,6 +98,8 @@ public:
*/ */
QString getTimeString(bool relative, QLocale::FormatType format = QLocale::ShortFormat, bool isPending = false, QDateTime lastUpdated = {}) const; 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. * @brief Whether the event should be highlighted in the timeline.
* *

View File

@@ -258,7 +258,7 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
}); });
auto lastUpdated = pendingIt == m_room->pendingEvents().cend() ? QDateTime() : pendingIt->lastUpdated(); 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) { if (role == AuthorRole) {
return QVariant::fromValue<NeochatRoomMember *>(m_eventSenderObject.get()); return QVariant::fromValue<NeochatRoomMember *>(m_eventSenderObject.get());