spoon

set dwm status
git clone git://git.2f30.org/spoon
Log | Files | Refs | LICENSE

commit a9d6d9a8effae85e7926661b9c46ae7474a95db6
parent 079812990cc3a3fec187a947c78194814d30dddf
Author: Lucas Gabriel Vuotto <lucas@nanashi.co>
Date:   Wed, 28 Mar 2018 19:47:04 -0300

Add support for multiple dates in different timezones

Signed-off-by: Lucas Gabriel Vuotto <lucas@nanashi.co>

Diffstat:
Mconfig.def.h | 2+-
Mdate.c | 14+++++++++++++-
Mtypes.h | 5+++++
3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -14,5 +14,5 @@ struct ent ents[] = { { .fmt = "[%s] ", .read = xkblayoutread, .arg = NULL }, { .fmt = "%s", .read = keyread, .arg = &(struct keyarg){ .sym = XK_Caps_Lock, .on = "[caps] ", .off = "" } }, { .fmt = "%s ", .read = fileread, .arg = "/etc/myname" }, - { .fmt = "%s", .read = dateread, .arg = "%a %d %b %Y %H:%M %Z" }, + { .fmt = "%s", .read = dateread, .arg = &(struct datearg){ .fmt = "%a %d %b %Y %H:%M %Z", .tz = NULL } }, }; diff --git a/date.c b/date.c @@ -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 @@ -13,3 +13,8 @@ struct keyarg { char *on; char *off; }; + +struct datearg { + char *fmt; + char *tz; +};