Commit: e7df6ef301f72cfc09be5941c6f479f2e9592c1a
Parent: a493e43360432a7a8b0f4095ffff96f7eeff7e02
Author: Randy Palamar
Date: Tue, 19 Jul 2022 11:05:09 -0600
rename gettime() to date() and follow other block conventions
Diffstat:
6 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/blocks/date.c b/blocks/date.c
@@ -0,0 +1,16 @@
+/* See LICENSE for license details. */
+#include <stdio.h>
+#include <time.h>
+
+#include "../status.h"
+#include "../util.h"
+#include "date.h"
+
+size_t
+date(struct Block *b)
+{
+ time_t t = time(NULL);
+ strftime(buf, sizeof(buf), b->u.s, localtime(&t));
+
+ return snprintf(b->curstr, LEN(b->curstr), b->fmt, buf);
+}
diff --git a/blocks/date.h b/blocks/date.h
@@ -0,0 +1 @@
+size_t date(struct Block *b);
diff --git a/blocks/gettime.c b/blocks/gettime.c
@@ -1,13 +0,0 @@
-/* See LICENSE for license details. */
-#include <time.h>
-
-#include "../status.h"
-#include "../util.h"
-#include "gettime.h"
-
-size_t
-gettime(struct Block *b)
-{
- time_t t = time(NULL);
- return strftime(b->curstr, LEN(b->curstr), b->fmt, localtime(&t));
-}
diff --git a/blocks/gettime.h b/blocks/gettime.h
@@ -1 +0,0 @@
-size_t gettime(struct Block *b);
diff --git a/config.def.h b/config.def.h
@@ -25,7 +25,7 @@ const char *alsacard = "default";
* batinfo battery percentage and status (.s) battery name (BAT0)
* 0 on OpenBSD
* blight backlight percentage (.s) backlight name (intel_backlight)
- * gettime date and time 0
+ * date date and time (.s) time fmt string (%R)
* getvol ALSA volume percentage (.s) sink name (Speaker)
* mpd_tag reads tag from current song (.i) enum mpd_tag_type (MPD_TAG_TITLE)
* script run specified script (.s) full script (echo foo | bar)
@@ -37,6 +37,6 @@ const char *alsacard = "default";
struct Block blks[] = {
/* fn fmt interval signal arg */
{ batinfo, "[ %s ]", 30, 0, { .s = "BAT0" } },
- { gettime, "[ %R ]", 20, 0, {0} },
+ { date, "[ %s ]", 20, 0, { .s = "%R" } },
{ NULL },
};
diff --git a/config.mk b/config.mk
@@ -1,5 +1,5 @@
SRC =\
- blocks/gettime.c\
+ blocks/date.c\
blocks/linux/battery.c\
blocks/linux/blight.c\
blocks/linux/volume.c\