Misc: Use host locale formatting for dates

Fixes achievement unlocks and lasted played times being shown in US
format.
pull/3493/head
Stenzek 4 months ago
parent 1c8699b8a0
commit 9b353f841e
No known key found for this signature in database

@ -3007,8 +3007,8 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
if (is_unlocked) if (is_unlocked)
{ {
TinyString date; const std::string date =
FullscreenUI::TimeToPrintableString(&date, cheevo->unlock_time); Host::FormatNumber(Host::NumberFormatType::ShortDateTime, static_cast<s64>(cheevo->unlock_time));
text.format(TRANSLATE_FS("Achievements", "Unlocked: {} | {:.1f}% of players have this achievement"), date, text.format(TRANSLATE_FS("Achievements", "Unlocked: {} | {:.1f}% of players have this achievement"), date,
rarity_to_display); 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; text_start_x += time_column_width + column_spacing;
const ImRect time_bb(ImVec2(text_start_x, bb.Min.y), ImVec2(bb.Max.x, midpoint)); 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<s64>(entry.submitted));
RenderShadowedTextClipped(UIStyle.Font, UIStyle.LargeFontSize, UIStyle.BoldFontWeight, time_bb.Min, time_bb.Max, 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); text_color, submit_time, nullptr, ImVec2(0.0f, 0.0f), 0.0f, &time_bb);

@ -583,19 +583,6 @@ static UIState s_state;
// Utility // Utility
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void FullscreenUI::TimeToPrintableString(SmallStringBase* str, time_t t)
{
struct tm lt = {};
#ifdef _MSC_VER
localtime_s(&lt, &t);
#else
localtime_r(&t, &lt);
#endif
char buf[256];
str->assign(buf, static_cast<u32>(std::strftime(buf, sizeof(buf), "%c", &lt)));
}
void FullscreenUI::GetStandardSelectionFooterText(SmallStringBase& dest, bool back_instead_of_cancel) void FullscreenUI::GetStandardSelectionFooterText(SmallStringBase& dest, bool back_instead_of_cancel)
{ {
if (IsGamepadInputSource()) if (IsGamepadInputSource())

@ -34,7 +34,6 @@ void OnSystemDestroyed();
void Shutdown(bool clear_state); void Shutdown(bool clear_state);
void Render(); void Render();
void InvalidateCoverCache(); void InvalidateCoverCache();
void TimeToPrintableString(SmallStringBase* str, time_t t);
float GetBackgroundAlpha(); float GetBackgroundAlpha();

@ -1275,27 +1275,14 @@ TinyString GameList::Entry::GetCompatibilityIconFileName() const
static_cast<u32>(dbentry ? dbentry->compatibility : GameDatabase::CompatibilityRating::Unknown)); static_cast<u32>(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) if (!dbentry || dbentry->release_date == 0)
{ ret = TRANSLATE_STR("GameList", "Unknown");
ret.append(TRANSLATE_SV("GameList", "Unknown"));
}
else else
{ ret = Host::FormatNumber(Host::NumberFormatType::LongDate, static_cast<s64>(dbentry->release_date));
std::time_t date_as_time = static_cast<std::time_t>(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<u32>(std::strftime(ret.data(), ret.buffer_size(), "%d %B %Y", &date_tm)));
}
return ret; return ret;
} }
@ -1548,13 +1535,13 @@ std::time_t GameList::GetCachedPlayedTimeForSerial(const std::string& serial)
return 0; 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) if (timestamp == 0)
{ {
ret = TRANSLATE("GameList", "Never"); ret = TRANSLATE_STR("GameList", "Never");
} }
else 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) 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)) || 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)) (ctime.tm_yday == 0 && (ctime.tm_year - 1) == ttime.tm_year))
{ {
ret = TRANSLATE("GameList", "Yesterday"); ret = TRANSLATE_STR("GameList", "Yesterday");
} }
else else
{ {
char buf[128]; ret = Host::FormatNumber(Host::NumberFormatType::ShortDate, static_cast<s64>(timestamp));
std::strftime(buf, std::size(buf), "%x", &ttime);
ret.assign(buf);
} }
} }

@ -65,7 +65,7 @@ struct Entry
TinyString GetLanguageIconName() const; TinyString GetLanguageIconName() const;
TinyString GetCompatibilityIconFileName() const; TinyString GetCompatibilityIconFileName() const;
TinyString GetReleaseDateString() const; std::string GetReleaseDateString() const;
ALWAYS_INLINE bool IsValid() const { return (type < EntryType::MaxCount); } ALWAYS_INLINE bool IsValid() const { return (type < EntryType::MaxCount); }
ALWAYS_INLINE bool IsDisc() const { return (type == EntryType::Disc); } 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); std::time_t GetCachedPlayedTimeForSerial(const std::string& serial);
/// Formats a timestamp to something human readable (e.g. Today, Yesterday, 10/11/12). /// 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). /// Formats a timespan to something human readable (e.g. 1h2m3s or 1 hour).
TinyString FormatTimespan(std::time_t timespan, bool long_format = false); TinyString FormatTimespan(std::time_t timespan, bool long_format = false);

Loading…
Cancel
Save