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

From: mtdxwb <zdx1314520666_AT_163.com>
Date: Tue, 3 Mar 2026 22:17:51 +0800

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);
+
+	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];
+
+	return bprintf("%s%s", icon, tmp);
 }
-- 
2.53.0
Received on Tue Mar 03 2026 - 15:17:51 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 03 2026 - 15:24:32 CET