diff --git a/lib/utils/mu-utils.cc b/lib/utils/mu-utils.cc index f32eed72..6a88788c 100644 --- a/lib/utils/mu-utils.cc +++ b/lib/utils/mu-utils.cc @@ -346,12 +346,9 @@ Mu::vformat(const char* frm, va_list args) } std::string -Mu::time_to_string(const std::string& frm_, time_t t, bool utc) +Mu::time_to_string(const char *frm, time_t t, bool utc) { - /* Temporary hack... https://github.com/djcb/mu/issues/2230 */ - const auto frm = - g_utf8_validate(frm_.c_str(), frm_.length(), {}) ? - frm_ : "%c"; + g_return_val_if_fail(frm, ""); GDateTime* dt = std::invoke([&] { if (utc) @@ -366,10 +363,11 @@ Mu::time_to_string(const std::string& frm_, time_t t, bool utc) return {}; } - auto datestr{to_string_opt_gchar(g_date_time_format(dt, frm.c_str()))}; + frm = frm ? frm : "%c"; + auto datestr{to_string_opt_gchar(g_date_time_format(dt, frm))}; g_date_time_unref(dt); if (!datestr) - g_warning("failed to format time with format '%s'", frm.c_str()); + g_warning("failed to format time with format '%s'", frm); return datestr.value_or(""); } diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh index dd38416c..4a9f70d6 100644 --- a/lib/utils/mu-utils.hh +++ b/lib/utils/mu-utils.hh @@ -153,7 +153,7 @@ std::string date_to_time_t_string(int64_t t); * @return a string representation of the time in UTF8-format, or empty in case * of error. */ -std::string time_to_string(const std::string& frm, time_t t, bool utc = false) G_GNUC_CONST; +std::string time_to_string(const char *frm, time_t t, bool utc = false) G_GNUC_CONST; /**