Make code identical for last_played_strftime and strftime_am_pm -

see opportunity here to cutdown on duplication and make this a public
function
This commit is contained in:
libretroadmin 2022-07-11 19:12:14 +02:00
parent e91cf0e40d
commit 6475d0ca54
2 changed files with 17 additions and 20 deletions

View File

@ -638,7 +638,7 @@ bool menu_entries_list_search(const char *needle, size_t *idx)
/* Time format strings with AM-PM designation require special /* Time format strings with AM-PM designation require special
* handling due to platform dependence */ * handling due to platform dependence */
static void strftime_am_pm(char* ptr, size_t maxsize, const char* format, static void strftime_am_pm(char *s, size_t len, const char* format,
const struct tm* timeptr) const struct tm* timeptr)
{ {
char *local = NULL; char *local = NULL;
@ -647,12 +647,12 @@ static void strftime_am_pm(char* ptr, size_t maxsize, const char* format,
* > Required for localised AM/PM strings */ * > Required for localised AM/PM strings */
setlocale(LC_TIME, ""); setlocale(LC_TIME, "");
strftime(ptr, maxsize, format, timeptr); strftime(s, len, format, timeptr);
#if !(defined(__linux__) && !defined(ANDROID)) #if !(defined(__linux__) && !defined(ANDROID))
local = local_to_utf8_string_alloc(ptr); local = local_to_utf8_string_alloc(s);
if (!string_is_empty(local)) if (!string_is_empty(local))
strlcpy(ptr, local, maxsize); strlcpy(s, local, len);
if (local) if (local)
{ {

View File

@ -625,30 +625,21 @@ void runtime_log_get_last_played_time(runtime_log_t *runtime_log,
mktime(time_info); mktime(time_info);
} }
static void last_played_strftime(runtime_log_t *runtime_log, static void last_played_strftime(char *s, size_t len, const char *format,
char *str, size_t len, const char *format) const struct tm *timeptr)
{ {
struct tm time_info;
char *local = NULL; char *local = NULL;
if (!runtime_log)
return;
/* Get time */
runtime_log_get_last_played_time(runtime_log, &time_info);
/* Ensure correct locale is set */ /* Ensure correct locale is set */
setlocale(LC_TIME, ""); setlocale(LC_TIME, "");
/* Generate string */ /* Generate string */
#if defined(__linux__) && !defined(ANDROID) strftime(s, len, format, timeptr);
strftime(str, len, format, &time_info); #if !(defined(__linux__) && !defined(ANDROID))
#else local = local_to_utf8_string_alloc(s);
strftime(str, len, format, &time_info);
local = local_to_utf8_string_alloc(str);
if (!string_is_empty(local)) if (!string_is_empty(local))
strlcpy(str, local, len); strlcpy(s, local, len);
if (local) if (local)
{ {
@ -860,7 +851,13 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log,
if (has_am_pm) if (has_am_pm)
{ {
last_played_strftime(runtime_log, tmp, sizeof(tmp), format_str); if (runtime_log)
{
/* Get time */
struct tm time_info;
runtime_log_get_last_played_time(runtime_log, &time_info);
last_played_strftime(tmp, sizeof(tmp), format_str, &time_info);
}
snprintf(str, len, "%s%s", snprintf(str, len, "%s%s",
msg_hash_to_str( msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED), MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),