From 16e8431a25e2fe2c83a7f2cf925eb4841ef7da69 Mon Sep 17 00:00:00 2001 From: Philip Kovacs Date: Sat, 15 Jul 2006 02:18:06 +0000 Subject: [PATCH] tztime patch git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@677 7f574dfc-610e-0410-a909-a81674777703 --- AUTHORS | 3 +++ ChangeLog | 4 ++++ doc/conky.1 | 4 ++++ doc/variables.xml | 20 ++++++++++++++++++++ src/conky.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+) diff --git a/AUTHORS b/AUTHORS index 8fb7486e..807c2a0b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -34,6 +34,9 @@ dan-h David McCabe utime +Ram Yalamanchili + tztime + Daniel Thiele APM support for FreeBSD diff --git a/ChangeLog b/ChangeLog index c4022648..91cd6112 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ # $Id$ +2006-07-13 + * Added tztime patch to show time in arbitrary time zones (thanks Ram + Yalamanchili) + 2006-06-07 * Small battery fix (thanks Nexox, sf.net patch 1500014) * Fixed order of variables/objects in docs (thanks Peter Tarjan) diff --git a/doc/conky.1 b/doc/conky.1 index 03a6681f..cdd1b1e1 100644 --- a/doc/conky.1 +++ b/doc/conky.1 @@ -889,6 +889,10 @@ Displays last N lines of supplied text text file. If interval is not supplied, C \fBtime\fR \fB(format)\fR Local time, see man strftime to get more information about format +.TP +\fBtztime\fR \fB(timezone) (format)\fR +Local time for specified timezone, see man strftime to get more information about format. The timezone argument is specified in similar fashion as TZ environment variable. For hints, look in /usr/share/zoneinfo. e.g. US/Pacific, Europe/Zurich, etc. + .TP \fBtotaldown\fR \fBnet\fR Total download, overflows at 4 GB on Linux with 32-bit arch and there doesn't seem to be a way to know how many times it has already done that before conky has started. diff --git a/doc/variables.xml b/doc/variables.xml index d7a1a9b3..ba48751e 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -1194,6 +1194,26 @@ + + + + + + + Display time in UTC (universal coordinate time). + + + + + + + + + + Local time for specified timezone, see man strftime to get more information about format. The timezone argument is specified in similar fashion as TZ environment variable. For hints, look in /usr/share/zoneinfo. e.g. US/Pacific, Europe/Zurich, etc. + + + diff --git a/src/conky.c b/src/conky.c index d25087e9..b6a5b3bf 100644 --- a/src/conky.c +++ b/src/conky.c @@ -934,6 +934,7 @@ enum text_object_type { OBJ_text, OBJ_time, OBJ_utime, + OBJ_tztime, OBJ_totaldown, OBJ_totalup, OBJ_updates, @@ -1050,6 +1051,12 @@ struct text_object { unsigned char loadavg[3]; unsigned int cpu_index; struct mail_s *mail; + + struct { + char *tz; /* timezone variable */ + char *fmt; /* time display formatting */ + } tztime; + struct { struct fs_stat *fs; int w, h; @@ -1707,6 +1714,12 @@ static void free_text_objects(unsigned int count, struct text_object *objs) free(objs[i].data.s); break; case OBJ_utime: + free(objs[i].data.s); + break; + case OBJ_tztime: + free(objs[i].data.tztime.tz); + free(objs[i].data.tztime.fmt); + break; case OBJ_imap: free(info.mail); break; @@ -2651,6 +2664,21 @@ static struct text_object *construct_text_object(const char *s, const char *arg, obj->data.i2c.devtype); END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T"); END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T"); + END OBJ(tztime, 0) + char buf1[256], buf2[256], *fmt, *tz; + fmt = tz = NULL; + if (arg) { + int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2); + switch (nArgs) { + case 2: + tz = buf1; + case 1: + fmt = buf2; + } + } + + obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T"); + obj->data.tztime.tz = tz ? strdup(tz) : NULL; #ifdef HAVE_ICONV END OBJ(iconv_start, 0) if (iconv_converting) { @@ -4102,6 +4130,25 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object * struct tm *tm = gmtime(&t); strftime(p, p_max_size, obj->data.s, tm); } + OBJ(tztime) { + char* oldTZ = NULL; + if (obj->data.tztime.tz) { + oldTZ = getenv("TZ"); + setenv("TZ", obj->data.tztime.tz, 1); + tzset(); + } + time_t t = time(NULL); + struct tm *tm = localtime(&t); + setlocale(LC_TIME, ""); + strftime(p, p_max_size, obj->data.tztime.fmt, tm); + if (oldTZ) { + setenv("TZ", oldTZ, 1); + tzset(); + } else { + unsetenv("TZ"); + } + // Needless to free oldTZ since getenv gives ptr to static data + } OBJ(totaldown) { human_readable(obj->data.net->recv, p, 255);