deraadt objected to the time zone validation. I don't care about the
feature and I agree with the point that I shouldn't do it because there
is no API for it. I don't even know where the time zone files are.
To make this all more symmetric always print tm_zone, even if TZ is not
set.
OK?
diff --git grdc.6 grdc.6
index 16e1758c6d2..5aa6e84a2d2 100644
--- grdc.6
+++ grdc.6
@@ -34,8 +34,11 @@ key exits the program.
.Bl -tag -width Ds
.It Ev TZ
The time zone to use for displaying the time.
-It is specified as a pathname relative to
-.Pa /usr/share/zoneinfo .
+It is normally specified as a pathname relative to
+.Pa /usr/share/zoneinfo ,
+though see
+.Xr tzset 3
+for more information.
If this variable is not set, the time zone is determined based on
.Pa /etc/localtime .
.El
diff --git grdc.c grdc.c
index 66e5eee79e6..01d29b08d64 100644
--- grdc.c
+++ grdc.c
@@ -12,6 +12,7 @@
*/
#include <sys/ioctl.h>
+#include <sys/stat.h>
#include <curses.h>
#include <err.h>
@@ -20,6 +21,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include <unistd.h>
@@ -78,9 +80,14 @@ main(int argc, char *argv[])
int xbase;
int ybase;
int wintoosmall;
+ int tz_len = 0;
+ int h, m;
+ int prev_tm_gmtoff;
char *tz;
tz = getenv("TZ");
+ if (tz != NULL)
+ tz_len = strlen(tz);
scrol = wintoosmall = 0;
while ((i = getopt(argc, argv, "sh")) != -1) {
@@ -135,6 +142,7 @@ main(int argc, char *argv[])
curs_set(0);
sigwinched = 1; /* force initial sizing */
+ prev_tm_gmtoff = 24 * 3600; /* force initial header printing */
clock_gettime(CLOCK_REALTIME, &now);
if (n) {
@@ -152,9 +160,11 @@ main(int argc, char *argv[])
set(tm->tm_hour / 10, 24);
set(10, 7);
set(10, 17);
- if (sigwinched) {
+ /* force repaint if window size changed or DST changed */
+ if (sigwinched || prev_tm_gmtoff != tm->tm_gmtoff) {
sigwinched = 0;
wintoosmall = 0;
+ prev_tm_gmtoff = tm->tm_gmtoff;
getwinsize(&i, &j);
if (i >= XLENGTH + 2)
xbase = (i - XLENGTH) / 2;
@@ -184,11 +194,19 @@ main(int argc, char *argv[])
move(ybase, xbase + XLENGTH);
vline(ACS_VLINE, YDEPTH);
- if (tz != NULL) {
- move(ybase - 1, xbase);
- printw("[ %s %+d ]", tz,
- tm->tm_gmtoff / 60 / 60 );
- }
+ move(ybase - 1, xbase);
+
+ h = tm->tm_gmtoff / 3600;
+ m = abs((int)tm->tm_gmtoff % 3600 / 60);
+
+ if (tz_len > 0 && tz_len <= XLENGTH -
+ strlen("[ () +0000 ]") -
+ strlen(tm->tm_zone))
+ printw("[ %s (%s) %+2.2d%02d ]", tz,
+ tm->tm_zone, h, m);
+ else
+ printw("[ %s %+2.2d%02d ]",
+ tm->tm_zone, h, m);
attrset(COLOR_PAIR(2));
}
--
I'm not entirely sure you are real.