diff --git a/src/core/achievements.cpp b/src/core/achievements.cpp index eec469f52..29aacf4ae 100644 --- a/src/core/achievements.cpp +++ b/src/core/achievements.cpp @@ -3007,8 +3007,8 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo) if (is_unlocked) { - TinyString date; - FullscreenUI::TimeToPrintableString(&date, cheevo->unlock_time); + const std::string date = + Host::FormatNumber(Host::NumberFormatType::ShortDateTime, static_cast(cheevo->unlock_time)); text.format(TRANSLATE_FS("Achievements", "Unlocked: {} | {:.1f}% of players have this achievement"), date, rarity_to_display); @@ -3496,8 +3496,9 @@ void Achievements::DrawLeaderboardEntry(const rc_client_leaderboard_entry_t& ent text_start_x += time_column_width + column_spacing; const ImRect time_bb(ImVec2(text_start_x, bb.Min.y), ImVec2(bb.Max.x, midpoint)); - SmallString submit_time; - FullscreenUI::TimeToPrintableString(&submit_time, entry.submitted); + + const std::string submit_time = + Host::FormatNumber(Host::NumberFormatType::ShortDateTime, static_cast(entry.submitted)); RenderShadowedTextClipped(UIStyle.Font, UIStyle.LargeFontSize, UIStyle.BoldFontWeight, time_bb.Min, time_bb.Max, text_color, submit_time, nullptr, ImVec2(0.0f, 0.0f), 0.0f, &time_bb); diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index 69908c68a..a1370b3f3 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -583,19 +583,6 @@ static UIState s_state; // Utility ////////////////////////////////////////////////////////////////////////// -void FullscreenUI::TimeToPrintableString(SmallStringBase* str, time_t t) -{ - struct tm lt = {}; -#ifdef _MSC_VER - localtime_s(<, &t); -#else - localtime_r(&t, <); -#endif - - char buf[256]; - str->assign(buf, static_cast(std::strftime(buf, sizeof(buf), "%c", <))); -} - void FullscreenUI::GetStandardSelectionFooterText(SmallStringBase& dest, bool back_instead_of_cancel) { if (IsGamepadInputSource()) diff --git a/src/core/fullscreen_ui.h b/src/core/fullscreen_ui.h index 18574a9a2..0a5c7f6be 100644 --- a/src/core/fullscreen_ui.h +++ b/src/core/fullscreen_ui.h @@ -34,7 +34,6 @@ void OnSystemDestroyed(); void Shutdown(bool clear_state); void Render(); void InvalidateCoverCache(); -void TimeToPrintableString(SmallStringBase* str, time_t t); float GetBackgroundAlpha(); diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index ebf65835d..dcb6bd0c4 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -1275,27 +1275,14 @@ TinyString GameList::Entry::GetCompatibilityIconFileName() const static_cast(dbentry ? dbentry->compatibility : GameDatabase::CompatibilityRating::Unknown)); } -TinyString GameList::Entry::GetReleaseDateString() const +std::string GameList::Entry::GetReleaseDateString() const { - TinyString ret; + std::string ret; if (!dbentry || dbentry->release_date == 0) - { - ret.append(TRANSLATE_SV("GameList", "Unknown")); - } + ret = TRANSLATE_STR("GameList", "Unknown"); else - { - std::time_t date_as_time = static_cast(dbentry->release_date); -#ifdef _WIN32 - tm date_tm = {}; - gmtime_s(&date_tm, &date_as_time); -#else - tm date_tm = {}; - gmtime_r(&date_as_time, &date_tm); -#endif - - ret.set_size(static_cast(std::strftime(ret.data(), ret.buffer_size(), "%d %B %Y", &date_tm))); - } + ret = Host::FormatNumber(Host::NumberFormatType::LongDate, static_cast(dbentry->release_date)); return ret; } @@ -1548,13 +1535,13 @@ std::time_t GameList::GetCachedPlayedTimeForSerial(const std::string& serial) return 0; } -TinyString GameList::FormatTimestamp(std::time_t timestamp) +std::string GameList::FormatTimestamp(std::time_t timestamp) { - TinyString ret; + std::string ret; if (timestamp == 0) { - ret = TRANSLATE("GameList", "Never"); + ret = TRANSLATE_STR("GameList", "Never"); } else { @@ -1571,18 +1558,16 @@ TinyString GameList::FormatTimestamp(std::time_t timestamp) if (ctime.tm_year == ttime.tm_year && ctime.tm_yday == ttime.tm_yday) { - ret = TRANSLATE("GameList", "Today"); + ret = TRANSLATE_STR("GameList", "Today"); } else if ((ctime.tm_year == ttime.tm_year && ctime.tm_yday == (ttime.tm_yday + 1)) || (ctime.tm_yday == 0 && (ctime.tm_year - 1) == ttime.tm_year)) { - ret = TRANSLATE("GameList", "Yesterday"); + ret = TRANSLATE_STR("GameList", "Yesterday"); } else { - char buf[128]; - std::strftime(buf, std::size(buf), "%x", &ttime); - ret.assign(buf); + ret = Host::FormatNumber(Host::NumberFormatType::ShortDate, static_cast(timestamp)); } } diff --git a/src/core/game_list.h b/src/core/game_list.h index c80d6a6d2..004ddc496 100644 --- a/src/core/game_list.h +++ b/src/core/game_list.h @@ -65,7 +65,7 @@ struct Entry TinyString GetLanguageIconName() const; TinyString GetCompatibilityIconFileName() const; - TinyString GetReleaseDateString() const; + std::string GetReleaseDateString() const; ALWAYS_INLINE bool IsValid() const { return (type < EntryType::MaxCount); } ALWAYS_INLINE bool IsDisc() const { return (type == EntryType::Disc); } @@ -125,7 +125,7 @@ void ClearPlayedTimeForEntry(const Entry* entry); std::time_t GetCachedPlayedTimeForSerial(const std::string& serial); /// Formats a timestamp to something human readable (e.g. Today, Yesterday, 10/11/12). -TinyString FormatTimestamp(std::time_t timestamp); +std::string FormatTimestamp(std::time_t timestamp); /// Formats a timespan to something human readable (e.g. 1h2m3s or 1 hour). TinyString FormatTimespan(std::time_t timespan, bool long_format = false);