tAdd support for multiple dates in different timezones - spoon - dwm status uti… | |
git clone git://src.adamsgaard.dk/spoon | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit a9d6d9a8effae85e7926661b9c46ae7474a95db6 | |
parent 079812990cc3a3fec187a947c78194814d30dddf | |
Author: Lucas Gabriel Vuotto <[email protected]> | |
Date: Wed, 28 Mar 2018 19:47:04 -0300 | |
Add support for multiple dates in different timezones | |
Signed-off-by: Lucas Gabriel Vuotto <[email protected]> | |
Diffstat: | |
M config.def.h | 2 +- | |
M date.c | 14 +++++++++++++- | |
M types.h | 5 +++++ | |
3 files changed, 19 insertions(+), 2 deletions(-) | |
--- | |
diff --git a/config.def.h b/config.def.h | |
t@@ -14,5 +14,5 @@ struct ent ents[] = { | |
{ .fmt = "[%s] ", .read = xkblayoutread, .arg = NULL }, | |
{ .fmt = "%s", .read = keyread, .arg = &(struct … | |
{ .fmt = "%s ", .read = fileread, .arg = "/etc/m… | |
- { .fmt = "%s", .read = dateread, .arg = "%a %d %… | |
+ { .fmt = "%s", .read = dateread, .arg = &(struct… | |
}; | |
diff --git a/date.c b/date.c | |
t@@ -1,18 +1,30 @@ | |
#include <sys/types.h> | |
#include <stdio.h> | |
+#include <stdlib.h> | |
#include <time.h> | |
+#include "types.h" | |
+ | |
int | |
dateread(void *arg, char *buf, size_t len) | |
{ | |
+ struct datearg *datearg = arg; | |
struct tm *now; | |
+ char *oldtz; | |
time_t t; | |
+ oldtz = getenv("TZ"); | |
+ if (datearg->tz != NULL && setenv("TZ", datearg->tz, 1) == 0) | |
+ tzset(); | |
t = time(NULL); | |
now = localtime(&t); | |
+ if (oldtz != NULL) | |
+ setenv("TZ", oldtz, 1); | |
+ else | |
+ unsetenv("TZ"); | |
if (now == NULL) | |
return -1; | |
- strftime(buf, len, arg, now); | |
+ strftime(buf, len, datearg->fmt, now); | |
return 0; | |
} | |
diff --git a/types.h b/types.h | |
t@@ -13,3 +13,8 @@ struct keyarg { | |
char *on; | |
char *off; | |
}; | |
+ | |
+struct datearg { | |
+ char *fmt; | |
+ char *tz; | |
+}; |