Core: Replace Timestamp usage with fmt

This commit is contained in:
Connor McLaughlin
2022-07-08 21:11:16 +10:00
parent b5bf3593c4
commit fd3507c16d
7 changed files with 66 additions and 19 deletions

View File

@ -3094,7 +3094,8 @@ std::vector<CommonHostInterface::SaveStateInfo> CommonHostInterface::GetAvailabl
if (!FileSystem::StatFile(path.c_str(), &sd))
return;
si.push_back(SaveStateInfo{std::move(path), sd.ModificationTime.AsUnixTimestamp(), static_cast<s32>(slot), global});
si.push_back(SaveStateInfo{std::move(path), static_cast<std::time_t>(sd.ModificationTime.AsUnixTimestamp()),
static_cast<s32>(slot), global});
};
if (game_code && std::strlen(game_code) > 0)
@ -3119,7 +3120,7 @@ std::optional<CommonHostInterface::SaveStateInfo> CommonHostInterface::GetSaveSt
if (!FileSystem::StatFile(path.c_str(), &sd))
return std::nullopt;
return SaveStateInfo{std::move(path), sd.ModificationTime.AsUnixTimestamp(), slot, global};
return SaveStateInfo{std::move(path), static_cast<std::time_t>(sd.ModificationTime.AsUnixTimestamp()), slot, global};
}
std::optional<CommonHostInterface::ExtendedSaveStateInfo>

View File

@ -4,6 +4,7 @@
#include "core/controller.h"
#include "core/host_interface.h"
#include <atomic>
#include <ctime>
#include <functional>
#include <map>
#include <memory>
@ -78,7 +79,7 @@ public:
struct SaveStateInfo
{
std::string path;
u64 timestamp;
std::time_t timestamp;
s32 slot;
bool global;
};
@ -89,7 +90,7 @@ public:
std::string title;
std::string game_code;
std::string media_path;
u64 timestamp;
std::time_t timestamp;
s32 slot;
bool global;

View File

@ -20,6 +20,8 @@
#include "core/resources.h"
#include "core/settings.h"
#include "core/system.h"
#include "fmt/chrono.h"
#include "fmt/format.h"
#include "fullscreen_ui_progress_callback.h"
#include "game_list.h"
#include "icon.h"
@ -2391,12 +2393,12 @@ void DrawSettingsWindow()
ActiveButton(SmallString::FromFormat(ICON_FA_USER " Username: %s", Cheevos::GetUsername().c_str()), false,
false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
Timestamp ts;
TinyString ts_string;
ts.SetUnixTimestamp(StringUtil::FromChars<u64>(s_host_interface->GetSettingsInterface()->GetStringValue(
"Cheevos", "LoginTimestamp", "0"))
.value_or(0));
ts.ToString(ts_string, "%Y-%m-%d %H:%M:%S");
ts_string.AppendFmtString(
"{:%Y-%m-%d %H:%M:%S}",
fmt::localtime(StringUtil::FromChars<u64>(
s_host_interface->GetSettingsInterface()->GetStringValue("Cheevos", "LoginTimestamp", "0"))
.value_or(0)));
ActiveButton(SmallString::FromFormat(ICON_FA_CLOCK " Login token generated on %s", ts_string.GetCharArray()),
false, false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
ImGui::PopStyleColor();
@ -2767,9 +2769,7 @@ void InitializeSaveStateListEntry(SaveStateListEntry* li, CommonHostInterface::E
li->title = StringUtil::StdStringFromFormat("%s Slot %d##game_slot_%d", ssi->title.c_str(), ssi->slot, ssi->slot);
}
li->summary =
StringUtil::StdStringFromFormat("%s - Saved %s", ssi->game_code.c_str(),
Timestamp::FromUnixTimestamp(ssi->timestamp).ToString("%c").GetCharArray());
li->summary = fmt::format("{} - Saved {:%c}", ssi->game_code.c_str(), fmt::localtime(ssi->timestamp));
li->slot = ssi->slot;
li->global = ssi->global;

View File

@ -4,6 +4,8 @@
#include "common/timestamp.h"
#include "core/host_display.h"
#include "core/system.h"
#include "fmt/chrono.h"
#include "fmt/format.h"
#include "icon.h"
#include "imgui.h"
Log_SetChannel(SaveStateSelectorUI);
@ -146,7 +148,7 @@ void SaveStateSelectorUI::InitializeListEntry(ListEntry* li, CommonHostInterface
li->title = std::move(ssi->title);
li->game_code = std::move(ssi->game_code);
li->path = std::move(ssi->path);
li->formatted_timestamp = Timestamp::FromUnixTimestamp(ssi->timestamp).ToString("%c");
li->formatted_timestamp = fmt::format("{:%c}", fmt::localtime(ssi->timestamp));
li->slot = ssi->slot;
li->global = ssi->global;