fix the timezones used for the user info box and add comments (#5162)

This commit is contained in:
ebbit1q 2024-11-05 20:54:38 +01:00 committed by GitHub
parent 11d58abbc3
commit 4d394c31f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View file

@ -138,17 +138,21 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user)
QString UserInfoBox::getAgeString(int ageSeconds)
{
QString accountAgeString = tr("Unknown");
if (ageSeconds == 0)
if (ageSeconds <= 0)
return accountAgeString;
auto date = QDateTime::fromSecsSinceEpoch(QDateTime::currentSecsSinceEpoch() - ageSeconds).date();
// secsSinceEpoch is in utc
auto secsSinceEpoch = QDateTime::currentSecsSinceEpoch() - ageSeconds;
// the date is in local time, fromSecsSinceEpoch expects a timestamp from utc and converts it to local time
auto date = QDateTime::fromSecsSinceEpoch(secsSinceEpoch).date();
if (!date.isValid())
return accountAgeString;
QString dateString = QLocale().toString(date, QLocale::ShortFormat);
// now can be local time as the date is also local time
auto now = QDate::currentDate();
auto daysAndYears = getDaysAndYearsBetween(date, now);
QString dateString = QLocale().toString(date, QLocale::ShortFormat);
QString yearString;
if (daysAndYears.second > 0) {
yearString = tr("%n Year(s), ", "amount of years (only shown if more than 0)", daysAndYears.second);

View file

@ -613,7 +613,8 @@ ServerInfo_User Servatrice_DatabaseInterface::evalUserQueryResult(const QSqlQuer
const QDateTime regDate = query->value(7).toDateTime();
if (!regDate.toString(Qt::ISODate).isEmpty()) {
qint64 accountAgeInSeconds = regDate.secsTo(QDateTime::currentDateTime());
// the registration date is in utc
qint64 accountAgeInSeconds = regDate.secsTo(QDateTime::currentDateTimeUtc());
result.set_accountage_secs(accountAgeInSeconds);
}