tAdd support for multiple dates in different timezones - spoon - dwm status utility (2f30 fork)
 (HTM) git clone git://src.adamsgaard.dk/spoon
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit a9d6d9a8effae85e7926661b9c46ae7474a95db6
 (DIR) parent 079812990cc3a3fec187a947c78194814d30dddf
 (HTM) 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:
         M config.def.h                        |       2 +-
         M date.c                              |      14 +++++++++++++-
         M types.h                             |       5 +++++
       
       3 files changed, 19 insertions(+), 2 deletions(-)
       ---
 (DIR) 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 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 } },
        };
 (DIR) 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;
        }
 (DIR) 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;
       +};