Re: [hackers] [PATCH v3] Add clock icons to datetime module

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri, 27 Mar 2026 16:09:52 +0100

On Fri, Mar 27, 2026 at 10:03:32PM +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:
> - Added error checks for time() and localtime()
> - Use tm->tm_hour directly instead of strftime+atoi
> - Removed unnecessary <stdlib.h>
> - Made icons array static
> ---
> components/datetime.c | 33 +++++++++++++++++++++++++++++++--
> 1 file changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/components/datetime.c b/components/datetime.c
> index 5b10daf..e7f0cb8 100644
> --- a/components/datetime.c
> +++ b/components/datetime.c
> _AT_@ -9,12 +9,41 @@ const char *
> datetime(const char *fmt)
> {
> time_t t;
> + struct tm *tm;
> + char hours[3];
This hours variable can be removed?


> + char tmp[BUFSIZ];
> + const char *icon = "\0";
> + static const char *icons[] = {
> + "󱐿 ", "󱑀 ", "󱑁 ", "󱑂 ",
> + "󱑃 ", "󱑄 ", "󱑅 ", "󱑆 ",
> + "󱑇 ", "󱑈 ", "󱑉 ", "󱑊 ",
> + };
> + int hour_int;
>
> t = time(NULL);
> - if (!strftime(buf, sizeof(buf), fmt, localtime(&t))) {
> + if (t == (time_t)-1) {
> + warn("time: Failed to get current time");
> + return NULL;
> + }
> +
> + tm = localtime(&t);
> + if (!tm) {
> + warn("localtime: Failed to convert time");
> + return NULL;
> + }
> +
> + if (!strftime(tmp, sizeof(tmp), fmt, tm)) {
> warn("strftime: Result string exceeds buffer size");
> return NULL;
> }
>
> - return buf;


> + strftime(hours, sizeof(hours), "%I", tm);

This strftime call is not needed anymore right?

> +
> + hour_int = tm->tm_hour % 12;
> + if (hour_int == 0)
> + hour_int = 12;
> +
> + icon = icons[hour_int - 1];
> +
> + return bprintf("%s%s", icon, tmp);
> }
> --
> 2.53.0
>
>

I'm not the maintainer. It seems like a fun patch to add this clock style :)

Is it intended for upstream? Otherwise you can upload it to the wiki.

Thanks for sharing!

-- 
Kind regards,
Hiltjo
Received on Fri Mar 27 2026 - 16:09:52 CET

This archive was generated by hypermail 2.3.0 : Fri Mar 27 2026 - 16:12:37 CET