1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-23 19:39:06 +00:00

tztime patch

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@677 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Philip Kovacs 2006-07-15 02:18:06 +00:00
parent 1c0acf9f50
commit 16e8431a25
5 changed files with 78 additions and 0 deletions

View File

@ -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

View File

@ -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)

View File

@ -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.

View File

@ -1194,6 +1194,26 @@
<para></para></listitem>
</varlistentry>
<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>

View 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);