utils: Handle failing g_date_time_new_...

Possibly, this caused a crashed under some scenarios (though couldn't reproduce).
This commit is contained in:
Dirk-Jan C. Binnema 2022-03-07 22:23:36 +02:00
parent 1fc0a6047f
commit 5b121352c2
1 changed files with 8 additions and 2 deletions

View File

@ -266,12 +266,18 @@ Mu::date_to_time_t_string(int64_t t)
std::string
Mu::time_to_string(const std::string& frm, time_t t, bool utc)
{
GDateTime* dt = [&] {
GDateTime* dt = std::invoke([&] {
if (utc)
return g_date_time_new_from_unix_utc(t);
else
return g_date_time_new_from_unix_local(t);
}();
});
if (!dt) {
g_warning("time_t out of range: <%" G_GUINT64_FORMAT ">",
static_cast<guint64>(t));
return {};
}
char* str = g_date_time_format(dt, frm.c_str());
g_date_time_unref(dt);