mirror of
https://github.com/stenzek/duckstation.git
synced 2025-07-28 22:01:59 +00:00
Misc: Use host locale formatting for dates
Fixes achievement unlocks and lasted played times being shown in US format.
This commit is contained in:
parent
1c8699b8a0
commit
9b353f841e
@ -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<s64>(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<s64>(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);
|
||||
|
||||
|
@ -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<u32>(std::strftime(buf, sizeof(buf), "%c", <)));
|
||||
}
|
||||
|
||||
void FullscreenUI::GetStandardSelectionFooterText(SmallStringBase& dest, bool back_instead_of_cancel)
|
||||
{
|
||||
if (IsGamepadInputSource())
|
||||
|
@ -34,7 +34,6 @@ void OnSystemDestroyed();
|
||||
void Shutdown(bool clear_state);
|
||||
void Render();
|
||||
void InvalidateCoverCache();
|
||||
void TimeToPrintableString(SmallStringBase* str, time_t t);
|
||||
|
||||
float GetBackgroundAlpha();
|
||||
|
||||
|
@ -1275,27 +1275,14 @@ TinyString GameList::Entry::GetCompatibilityIconFileName() const
|
||||
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)
|
||||
{
|
||||
ret.append(TRANSLATE_SV("GameList", "Unknown"));
|
||||
}
|
||||
ret = TRANSLATE_STR("GameList", "Unknown");
|
||||
else
|
||||
{
|
||||
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)));
|
||||
}
|
||||
ret = Host::FormatNumber(Host::NumberFormatType::LongDate, static_cast<s64>(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<s64>(timestamp));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user