From 3bf72210e1650a00a7ee3f434c3be0d6258b5b5e Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 1 Apr 2025 12:19:47 +0200 Subject: [PATCH] Add `iso8601` when setting a time format Instead of manually typing the format-string, one can now simply use `iso8601`. Signed-off-by: Steffen Jaeckel --- src/command/cmd_defs.c | 6 ++++-- src/command/cmd_funcs.c | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 8c3c3d24..591b3d48 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1190,7 +1190,8 @@ static const struct cmd_t command_defs[] = { "Time formats are strings supported by g_date_time_format. " "See https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format for more details. " "Setting the format to an unsupported string, will display the string. " - "If the format contains spaces, it must be surrounded with double quotes.") + "If the format contains spaces, it must be surrounded with double quotes. " + "It is possible to pass format as 'iso8601' in order to set the time format according to ISO-8601 (only local time, without Time zone designator).") CMD_ARGS( { "console set ", "Set time format for console window." }, { "console off", "Do not show time in console window." }, @@ -1216,7 +1217,8 @@ static const struct cmd_t command_defs[] = { "/time xml off", "/time statusbar set %H:%M", "/time lastactivity set \"%d-%m-%y %H:%M:%S\"", - "/time all set \"%d-%m-%y %H:%M:%S\"") + "/time all set \"%d-%m-%y %H:%M:%S\"", + "/time all set iso8601") }, { CMD_PREAMBLE("/inpblock", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 19ef4889..7bc19040 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5326,7 +5326,20 @@ cmd_time(ProfWin* window, const char* const command, gchar** args) auto_gchar gchar* format = prefs_get_string(tp->pref); cons_show("%s time format: '%s'.", tp->description, format); } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { - prefs_set_string(tp->pref, args[2]); + const struct format_strings + { + const char *name, *format; + } format_strings[] = { + { .name = "iso8601", .format = "%Y-%m-%dT%H:%M:%S" }, + }; + const gchar* set_arg = args[2]; + for (size_t m = 0; m < ARRAY_SIZE(format_strings); ++m) { + if (g_strcmp0(args[2], format_strings[m].name) == 0) { + set_arg = format_strings[m].format; + break; + } + } + prefs_set_string(tp->pref, set_arg); cons_show("%s time format set to '%s'.", tp->description, args[2]); redraw = TRUE; } else if (g_strcmp0(args[1], "off") == 0) {