chatview: timestamp improvements

New timestamp computation and sequencing ( by day and hour)

GitLab: #827
Change-Id: Ie170f31c075dc37f00d393272410329dc045f2d3
This commit is contained in:
Nicolas
2022-09-12 09:36:50 -04:00
committed by Nicolas Vengeon
parent c3e8e38e99
commit d6ed9adf32
14 changed files with 366 additions and 255 deletions

View File

@@ -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;
}