tztime patch
authorPhilip Kovacs <pkovacs@users.sourceforge.net>
Sat, 15 Jul 2006 02:18:06 +0000 (02:18 +0000)
committerPhilip Kovacs <pkovacs@users.sourceforge.net>
Sat, 15 Jul 2006 02:18:06 +0000 (02:18 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@677 7f574dfc-610e-0410-a909-a81674777703

AUTHORS
ChangeLog
doc/conky.1
doc/variables.xml
src/conky.c

diff --git a/AUTHORS b/AUTHORS
index 8fb7486..807c2a0 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -34,6 +34,9 @@ dan-h <dan-h at users dot sourceforge dot net>
 David McCabe
   utime
 
+Ram Yalamanchili
+  tztime
+
 Daniel Thiele <dthiele at gmx dot net>
   APM support for FreeBSD
 
index c402264..91cd611 100644 (file)
--- 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)
index 03a6681..cdd1b1e 100644 (file)
@@ -890,6 +890,10 @@ Displays last N lines of supplied text text file. If interval is not supplied, C
 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.
 
index d7a1a9b..ba48751 100644 (file)
 
 <varlistentry>
        <term>
+               <command><option>utime</option></command>
+       <option>(format)</option>
+       </term>
+       <listitem>
+               Display time in UTC (universal coordinate time).
+       <para></para></listitem>
+</varlistentry>
+
+<varlistentry>
+       <term>
+               <command><option>tztime</option></command>
+       <option>(timezone) (format)</option>
+       </term>
+       <listitem>
+               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.
+       <para></para></listitem>
+</varlistentry>
+
+<varlistentry>
+       <term>
                <command><option>totaldown</option></command>
        <option>net</option>
        </term>
index d25087e..b6a5b3b 100644 (file)
@@ -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);