mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 11:03:54 -07:00
fix the timezones used for the user info box and add comments (#5162)
This commit is contained in:
parent
11d58abbc3
commit
4d394c31f9
2 changed files with 9 additions and 4 deletions
|
|
@ -138,17 +138,21 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
||||||
QString UserInfoBox::getAgeString(int ageSeconds)
|
QString UserInfoBox::getAgeString(int ageSeconds)
|
||||||
{
|
{
|
||||||
QString accountAgeString = tr("Unknown");
|
QString accountAgeString = tr("Unknown");
|
||||||
if (ageSeconds == 0)
|
if (ageSeconds <= 0)
|
||||||
return accountAgeString;
|
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())
|
if (!date.isValid())
|
||||||
return accountAgeString;
|
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 now = QDate::currentDate();
|
||||||
auto daysAndYears = getDaysAndYearsBetween(date, now);
|
auto daysAndYears = getDaysAndYearsBetween(date, now);
|
||||||
|
|
||||||
|
QString dateString = QLocale().toString(date, QLocale::ShortFormat);
|
||||||
QString yearString;
|
QString yearString;
|
||||||
if (daysAndYears.second > 0) {
|
if (daysAndYears.second > 0) {
|
||||||
yearString = tr("%n Year(s), ", "amount of years (only shown if more than 0)", daysAndYears.second);
|
yearString = tr("%n Year(s), ", "amount of years (only shown if more than 0)", daysAndYears.second);
|
||||||
|
|
|
||||||
|
|
@ -613,7 +613,8 @@ ServerInfo_User Servatrice_DatabaseInterface::evalUserQueryResult(const QSqlQuer
|
||||||
|
|
||||||
const QDateTime regDate = query->value(7).toDateTime();
|
const QDateTime regDate = query->value(7).toDateTime();
|
||||||
if (!regDate.toString(Qt::ISODate).isEmpty()) {
|
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);
|
result.set_accountage_secs(accountAgeInSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue