Files
neochat/src/libneochat/neochatdatetime.cpp
Darshan Phaldesai 1289194b3f Messages: Make the Date/Timestamps more usable
Previously timestamps were in the right-hand side of the messages which made it very hard to relate timestamps with their corresponding messages. 
Moving them right next to the name makes much better UX wise (and surprisingly didn't make the UI too crowded). I have tested this in dark light and bubbles mode, and it all looks good and comfortable to me.

I have also tweaked how the timestamps are formatted. 
- For messages on the same day, it will skip the date part.
- For recent days, it uses relative timestamp (yesterday, XX:XX) 
- For everything before its shows short form date and time

The tooltip now uses Long Format of Date and Time.
2026-02-10 19:32:36 -05:00

66 lines
1.5 KiB
C++

// SPDX-FileCopyrightText: 2026 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include "neochatdatetime.h"
#include <KFormat>
using namespace Qt::Literals::StringLiterals;
NeoChatDateTime::NeoChatDateTime(QDateTime dateTime)
: m_dateTime(dateTime)
{
}
QDateTime NeoChatDateTime::dateTime() const
{
return m_dateTime;
}
QString NeoChatDateTime::hourMinuteString() const
{
return m_dateTime.toLocalTime().toString(u"hh:mm"_s);
}
QString NeoChatDateTime::shortDateTime() const
{
return QLocale().toString(m_dateTime.toLocalTime(), QLocale::ShortFormat);
}
QString NeoChatDateTime::longDateTime() const
{
return QLocale().toString(m_dateTime.toLocalTime(), QLocale::LongFormat);
}
QString NeoChatDateTime::relativeDate() const
{
KFormat formatter;
return formatter.formatRelativeDate(m_dateTime.toLocalTime().date(), QLocale::ShortFormat);
}
QString NeoChatDateTime::relativeDateTime() const
{
KFormat formatter;
return formatter.formatRelativeDateTime(m_dateTime.toLocalTime(), QLocale::ShortFormat);
}
QString NeoChatDateTime::shortRelativeDateTime() const
{
if (m_dateTime > QDate::currentDate().startOfDay()) {
return hourMinuteString();
}
return relativeDate() + u", "_s + hourMinuteString();
}
bool NeoChatDateTime::isValid() const
{
return m_dateTime.isValid();
}
bool NeoChatDateTime::operator==(const QDateTime &right) const
{
return m_dateTime == right;
}
#include "moc_neochatdatetime.cpp"