SaveState Manager: Format specially close dates

This commit is contained in:
Elad 2025-10-20 16:19:37 +03:00
parent c683b47ac3
commit abad7f2790
3 changed files with 17 additions and 4 deletions

View File

@ -664,9 +664,22 @@ namespace gui
return dateTime;
}
QString format_datetime(const QDateTime& date, const QString& fmt)
QString format_datetime(const QDateTime& date, const QString& fmt, bool is_relative, const QString& fmt_relative)
{
return date.toString(fmt);
const qint64 exctrated_date = date.date().toJulianDay();
const qint64 current_date = QDate::currentDate().toJulianDay();
if (!is_relative || exctrated_date > current_date || current_date - exctrated_date >= 3)
{
return date.toString(fmt);
}
if (current_date == exctrated_date)
{
return QString("Today %1").arg(date.toString(fmt_relative));
}
return QString("%1 days ago %2").arg(current_date - exctrated_date).arg(date.toString(fmt_relative));
}
QString format_timestamp(s64 time, const QString& fmt)

View File

@ -161,7 +161,7 @@ namespace gui
QDateTime datetime(s64 time);
// Convert a QDateTime to a readable string
QString format_datetime(const QDateTime& date, const QString& fmt = "yyyy-MM-dd HH:mm:ss");
QString format_datetime(const QDateTime& date, const QString& fmt = "yyyy-MM-dd HH:mm:ss", bool is_relative = false, const QString& fmt_relative = "HH:mm:ss");
// Convert a timestamp to a readable string
QString format_timestamp(s64 time, const QString& fmt = "yyyy-MM-dd HH:mm:ss");

View File

@ -686,7 +686,7 @@ void savestate_manager_dialog::PopulateSavestateTable()
const savestate_data& savestate = savestates[i];
m_savestate_table->setItem(i, static_cast<int>(gui::savestate_list_columns::name), new custom_table_widget_item(savestate.name));
m_savestate_table->setItem(i, static_cast<int>(gui::savestate_list_columns::compatible), new custom_table_widget_item(savestate.is_compatible ? tr("Compatible") : tr("Not compatible"), Qt::UserRole, savestate.is_compatible));
m_savestate_table->setItem(i, static_cast<int>(gui::savestate_list_columns::date), new custom_table_widget_item(gui::utils::format_datetime(savestate.date), Qt::UserRole, savestate.date));
m_savestate_table->setItem(i, static_cast<int>(gui::savestate_list_columns::date), new custom_table_widget_item(gui::utils::format_datetime(savestate.date, "yyyy-MM-dd HH:mm", true, "HH:mm"), Qt::UserRole, savestate.date));
m_savestate_table->setItem(i, static_cast<int>(gui::savestate_list_columns::path), new custom_table_widget_item(savestate.path));
}