mirror of
https://github.com/savoirfairelinux/jami-client-qt.git
synced 2025-12-26 17:37:00 +08:00
chatview: timestamp improvements
New timestamp computation and sequencing ( by day and hour) GitLab: #827 Change-Id: Ie170f31c075dc37f00d393272410329dc045f2d3
This commit is contained in:
@@ -581,21 +581,41 @@ MessagesAdapter::getFormattedTime(const quint64 timestamp)
|
||||
{
|
||||
const auto now = QDateTime::currentDateTime();
|
||||
const auto seconds = now.toSecsSinceEpoch() - timestamp;
|
||||
auto interval = qFloor(seconds / (3600 * 24));
|
||||
if (interval > 5)
|
||||
return QLocale::system().toString(QDateTime::fromSecsSinceEpoch(timestamp),
|
||||
QLocale::ShortFormat);
|
||||
if (interval > 1)
|
||||
return QObject::tr("%1 days ago").arg(interval);
|
||||
if (interval == 1)
|
||||
return QObject::tr("one day ago");
|
||||
interval = qFloor(seconds / 3600);
|
||||
if (interval > 1)
|
||||
return QObject::tr("%1 hours ago").arg(interval);
|
||||
if (interval == 1)
|
||||
return QObject::tr("one hour ago");
|
||||
interval = qFloor(seconds / 60);
|
||||
if (interval > 1)
|
||||
return QObject::tr("%1 minutes ago").arg(interval);
|
||||
auto interval = qFloor(seconds / 60);
|
||||
|
||||
if (interval > 1) {
|
||||
auto curLang = settingsManager_->getValue(Settings::Key::LANG);
|
||||
auto curLocal(QLocale(curLang.toString()));
|
||||
auto curTime = QDateTime::fromSecsSinceEpoch(timestamp).time();
|
||||
QString timeLocale;
|
||||
if (curLang == "SYSTEM")
|
||||
timeLocale = QLocale::system().toString(curTime, QLocale::system().ShortFormat);
|
||||
else
|
||||
timeLocale = curLocal.toString(curTime, curLocal.ShortFormat);
|
||||
|
||||
return timeLocale;
|
||||
}
|
||||
return QObject::tr("just now");
|
||||
}
|
||||
|
||||
QString
|
||||
MessagesAdapter::getFormattedDay(const quint64 timestamp)
|
||||
{
|
||||
auto now = QDate::currentDate();
|
||||
auto before = QDateTime::fromSecsSinceEpoch(timestamp).date();
|
||||
if (before == now)
|
||||
return QObject::tr("Today");
|
||||
if (before.daysTo(now) == 1)
|
||||
return QObject::tr("Yesterday");
|
||||
|
||||
auto curLang = settingsManager_->getValue(Settings::Key::LANG);
|
||||
auto curLocal(QLocale(curLang.toString()));
|
||||
auto curDate = QDateTime::fromSecsSinceEpoch(timestamp).date();
|
||||
QString dateLocale;
|
||||
if (curLang == "SYSTEM")
|
||||
dateLocale = QLocale::system().toString(curDate, QLocale::system().ShortFormat);
|
||||
else
|
||||
dateLocale = curLocal.toString(curDate, curLocal.ShortFormat);
|
||||
|
||||
return dateLocale;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user