diff options
author | Frederic Martinsons <frederic.martinsons@sigfox.com> | 2021-10-15 08:38:50 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2021-10-22 13:48:13 +0200 |
commit | 0510e9aef8818eeaa445aea246b670871c671ddb (patch) | |
tree | 131380f2a6d70eeb880cbe9b216ef006b4eb1604 /libmm-glib/mm-common-helpers.c | |
parent | 53bcdaa8c3962abbf2a2f638c64173a7657ab560 (diff) |
api,bearer: new 'start-date' field in bearer statistics
It stores the epoch timestamp of the current bearer session start.
If there is no connected bearer, it is set to 0 and not displayed
in mmcli output.
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
Includes updates by Aleksander Morgado to fix coding style issues.
Diffstat (limited to 'libmm-glib/mm-common-helpers.c')
-rw-r--r-- | libmm-glib/mm-common-helpers.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 1f146f6f..6f0a4929 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1661,6 +1661,47 @@ mm_get_string_unquoted_from_match_info (GMatchInfo *match_info, return str; } +gchar * +mm_format_iso8601 (guint64 timestamp) +{ + gchar *format_date = NULL; + GDateTime *datetime = NULL; + + datetime = g_date_time_new_from_unix_utc ((gint64)timestamp); + +#if GLIB_CHECK_VERSION (2, 62, 0) + format_date = g_date_time_format_iso8601 (datetime); +#else + { + GString *outstr = NULL; + gchar *main_date = NULL; + gint64 offset = 0; + + main_date = g_date_time_format (datetime, "%Y-%m-%dT%H:%M:%S"); + outstr = g_string_new (main_date); + g_free (main_date); + + /* Timezone. Format it as `%:::z` unless the offset is zero, in which case + * we can simply use `Z`. */ + offset = g_date_time_get_utc_offset (datetime); + + if (offset == 0) { + g_string_append_c (outstr, 'Z'); + } else { + gchar *time_zone; + + time_zone = g_date_time_format (datetime, "%:::z"); + g_string_append (outstr, time_zone); + g_free (time_zone); + } + + format_date = g_string_free (outstr, FALSE); + } +#endif + g_date_time_unref (datetime); + return format_date; +} + /*****************************************************************************/ /* From hostap, Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi> */ |