Re: [hackers] [PATCH v2] Add clock icons to datetime module(v2)

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sat, 21 Mar 2026 16:35:08 +0100

On Sat, Mar 21, 2026 at 08:23:28PM +0800, mtdxwb wrote:
> This patch adds Nerd Font clock icons that change according to the
> current hour (12-hour format). The icons are chosen based on the
> hour string extracted via strftime(%I).
>
> Changes:
> - Moved variable declaration to function top
> ---
> components/datetime.c | 23 +++++++++++++++++++++--
> 1 file changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/components/datetime.c b/components/datetime.c
> index 5b10daf..e810973 100644
> --- a/components/datetime.c
> +++ b/components/datetime.c
> _AT_@ -1,6 +1,7 @@
> /* See LICENSE file for copyright and license details. */
> #include <stdio.h>
> #include <time.h>
> +#include <stdlib.h>
>
> #include "../slstatus.h"
> #include "../util.h"
> _AT_@ -9,12 +10,30 @@ const char *
> datetime(const char *fmt)
> {
> time_t t;
> + struct tm *tm;
> + char hours[3];
> + char tmp[BUFSIZ];
> + const char *icon = "\0";
> + const char *icons[] = {
> + "󱐿 ", "󱑀 ", "󱑁 ", "󱑂 ",
> + "󱑃 ", "󱑄 ", "󱑅 ", "󱑆 ",
> + "󱑇 ", "󱑈 ", "󱑉 ", "󱑊 ",
> + };
> + int hour_int;
>
> t = time(NULL);
> - if (!strftime(buf, sizeof(buf), fmt, localtime(&t))) {
> + tm = localtime(&t);
> +

Probably needs some checking of tm == NULL just in case, maybe even time(NULL) == (time_t)-1..

> + if (!strftime(tmp, sizeof(tmp), fmt, tm)) {
> warn("strftime: Result string exceeds buffer size");
> return NULL;
> }
>
> - return buf;
> + strftime(hours, sizeof(hours), "%I", tm);
> +
> + hour_int = atoi(hours);
> + if (hour_int >= 1 && hour_int <= 12)
> + icon = icons[hour_int - 1];
> +

tm.tm_hour could be used maybe?

> + return bprintf("%s%s", icon, tmp);
> }
> --
> 2.53.0
>
>

-- 
Kind regards,
Hiltjo
Received on Sat Mar 21 2026 - 16:35:08 CET

This archive was generated by hypermail 2.3.0 : Sat Mar 21 2026 - 16:36:38 CET