Date patch to xplot

From: brian utterback (brian.utterback@Sun.COM)
Date: 04/23/01


Message-ID: <3AE46795.F4910C1E@Sun.COM>
Date: Mon, 23 Apr 2001 13:34:13 -0400
From: brian utterback <brian.utterback@Sun.COM>
Subject: Date patch to xplot


A year or so ago I noticed a small bug in xplot that prevented it from printing
the date info like intended. Ever notice how it seems to pick an odd time at
the
tic values when the graph is using timevals and covers several days? The reason
is
that xplot is supposed to print the date at the midnight tic, but it uses UTC to
choose the tics on the axis, but formats them with local time. So, the time
displayed
is UTC midnight, but it is formatted as local time, which shows no date.

Luckily, there is a nice Posix compliant solution, so I coded up the fix. It
gets a
little flaky if the time displayed happens to include daylight savings time
changes,
but ce la vie. I couldn't figure out an elegant solution so I went with the best
I could think of.

-- 
blu
______________________________________________________________________
One of Sun's competitors printed T-shirts that proclaimed,
"The network is the network and the computer is the computer." 
Today that firm is, of course, dead.
			-Harris Kern & Randy Johnson - ITworld.com

*** timeval.c Fri Jun 28 15:41:21 1996 --- /usr/tools/src/jedi/src/xplot-0.90/timeval.c Fri Jan 21 14:00:32 2000 *************** *** 38,43 **** --- 38,48 ---- #include "xplot.h" #include "coord.h" + extern time_t timezone, altzone; + extern int daylight; + extern char *tzname[2]; + + inline static void timeval_fix(coord *r) *************** *** 171,182 **** { coord r; struct tm *tmp; tmp = localtime((time_t *) &(c1.t.tv_sec)); - #ifdef TM_GMTOFF c1.t.tv_sec += tmp->tm_gmtoff; #endif if (c2.t.tv_sec == 0) { r.t.tv_sec = c1.t.tv_sec; --- 176,195 ---- { coord r; struct tm *tmp; + time_t gmtoff; tmp = localtime((time_t *) &(c1.t.tv_sec)); #ifdef TM_GMTOFF c1.t.tv_sec += tmp->tm_gmtoff; #endif + if (tmp->tm_isdst==0) { + gmtoff = -timezone; + } else if (tmp->tm_isdst==1) { + gmtoff = -altzone; + } else { + gmtoff = 0; + } + c1.t.tv_sec += gmtoff; if (c2.t.tv_sec == 0) { r.t.tv_sec = c1.t.tv_sec; *************** *** 186,194 **** r.t.tv_sec = c1.t.tv_sec - (c1.t.tv_sec % c2.t.tv_sec); } ! #ifdef TM_GMTOFF ! r.t.tv_sec -= tmp->tm_gmtoff; ! #endif timeval_fix(&r); return r; --- 199,205 ---- r.t.tv_sec = c1.t.tv_sec - (c1.t.tv_sec % c2.t.tv_sec); } ! r.t.tv_sec -= gmtoff; timeval_fix(&r); return r; *************** *** 199,204 **** --- 210,216 ---- { coord r; struct tm *tmp; + time_t gmtoff; tmp = localtime((time_t *) &(c1.t.tv_sec)); *************** *** 205,210 **** --- 217,230 ---- #ifdef TM_GMTOFF c1.t.tv_sec += tmp->tm_gmtoff; #endif + if (tmp->tm_isdst==0) { + gmtoff = -timezone; + } else if (tmp->tm_isdst==1) { + gmtoff = -altzone; + } else { + gmtoff = 0; + } + c1.t.tv_sec += gmtoff; if (c2.t.tv_sec == 0) { r.t.tv_sec = c1.t.tv_sec; *************** *** 226,234 **** r.t.tv_sec = c1.t.tv_sec + (c2.t.tv_sec - (c1.t.tv_sec % c2.t.tv_sec)); } ! #ifdef TM_GMTOFF ! r.t.tv_sec -= tmp->tm_gmtoff; ! #endif timeval_fix(&r); return r; --- 246,252 ---- r.t.tv_sec = c1.t.tv_sec + (c2.t.tv_sec - (c1.t.tv_sec % c2.t.tv_sec)); } ! r.t.tv_sec -= gmtoff; timeval_fix(&r); return r; *************** *** 303,309 **** coord timeval_tick(int level) { coord r; ! extern void panic(); if (level < 0 || level >= sizeof(tick_table) / sizeof(struct tick_table_s)) --- 321,327 ---- coord timeval_tick(int level) { coord r; ! extern void ianic(); if (level < 0 || level >= sizeof(tick_table) / sizeof(struct tick_table_s))


---------------------------------------------------------------------------- To unsubscribe, send a message with body containing "unsubscribe tcptrace" to majordomo@tcptrace.org.



This archive was generated by hypermail 2b30 : 04/24/01 EDT