[hackers] [slstatus][PATCH] Add clock icons to datetime module

From: mtdxwb <zdx1314520666_AT_163.com>
Date: Sat, 28 Mar 2026 15:43:17 +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:
- Removed unused hours variable
- Removed useless strftime call
---
 components/datetime.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/components/datetime.c b/components/datetime.c
index 5b10daf..2bc684f 100644
--- a/components/datetime.c
+++ b/components/datetime.c
_AT_@ -9,12 +9,38 @@ const char *
 datetime(const char *fmt)
 {
 	time_t t;
+	struct tm *tm;
+	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;
+	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
Received on Sat Mar 28 2026 - 08:43:17 CET

This archive was generated by hypermail 2.3.0 : Sat Mar 28 2026 - 08:48:38 CET