9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.05.19.21.24.56; author jromine; state Exp;
19 date 92.05.19.21.24.42; author jromine; state Exp;
24 date 92.05.15.17.56.29; author jromine; state Exp;
29 date 92.02.07.00.45.31; author jromine; state Exp;
34 date 92.02.07.00.27.17; author jromine; state Exp;
39 date 92.02.05.23.45.46; author jromine; state Exp;
44 date 92.02.05.22.39.47; author jromine; state Exp;
49 date 90.04.09.13.23.19; author sources; state Exp;
54 date 90.04.05.15.04.43; author sources; state Exp;
59 date 90.02.22.18.14.11; author sources; state Exp;
64 date 90.02.22.18.09.06; author sources; state Exp;
69 date 90.02.22.14.34.23; author sources; state Exp;
74 date 90.02.01.14.37.05; author sources; state Exp;
79 date 90.02.01.14.36.51; author sources; state Exp;
93 @/* dtime.c - routines to do ``ARPA-style'' time structures */
95 static char ident[] = "@@(#)$Id: dtime.c,v 1.14 1992/05/19 21:24:56 jromine Exp jromine $";
103 #include "../h/strings.h"
106 #endif /* INETONLY */
108 #include <sys/types.h>
109 #if !defined(SYS5) && !defined(ZONEINFO)
110 #include <sys/timeb.h>
111 #endif /* !defined(SYS5) && !defined(ZONEINFO) */
113 #include <sys/time.h>
117 #include <sys/time.h>
125 extern long timezone;
126 extern char *tzname[];
132 #define abs(a) (a >= 0 ? a : -a)
136 (((y) % 4) ? 365 : (((y) % 100) ? 366 : (((y) % 400) ? 365 : 366)))
141 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
142 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL
146 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
150 "Sunday", "Monday", "Tuesday", "Wednesday",
151 "Thursday", "Friday", "Saturday", NULL
166 #ifdef notdef /* RFC1123 specifies do not use military TZs */
203 struct tm *localtime ();
210 (void) time (&clock);
211 return dtime (&clock);
216 register struct tws *tw;
218 static char buffer[25];
223 (void) sprintf (buffer, "%.3s %.3s %02d %02d:%02d:%02d %.4d\n",
224 tw_dotw[tw -> tw_wday], tw_moty[tw -> tw_mon], tw -> tw_mday,
225 tw -> tw_hour, tw -> tw_min, tw -> tw_sec,
226 tw -> tw_year >= 100 ? tw -> tw_year : CENTURY + tw -> tw_year);
233 struct tws *dtwstime () {
236 (void) time (&clock);
237 return dlocaltime (&clock);
241 struct tws *dlocaltime (clock)
242 register long *clock;
244 register struct tm *tm;
245 #if !defined(SYS5) && !defined(ZONEINFO)
247 #endif /* !defined(SYS5) && !defined(ZONEINFO) */
248 static struct tws tw;
252 tw.tw_flags = TW_NULL;
254 tm = localtime (clock);
255 tw.tw_sec = tm -> tm_sec;
256 tw.tw_min = tm -> tm_min;
257 tw.tw_hour = tm -> tm_hour;
258 tw.tw_mday = tm -> tm_mday;
259 tw.tw_mon = tm -> tm_mon;
260 tw.tw_year = tm -> tm_year + CENTURY;
261 tw.tw_wday = tm -> tm_wday;
262 tw.tw_yday = tm -> tm_yday;
264 tw.tw_flags |= TW_DST;
267 tw.tw_zone = -(timezone / 60);
268 #else /* defined(SYS5) */
269 #if defined(ZONEINFO)
270 tw.tw_zone = tm->tm_gmtoff / 60;
271 if (tm -> tm_isdst) /* if DST is in effect */
272 tw.tw_zone -= 60; /* reset to normal offset */
273 #else /* defined(ZONEINFO) */
275 tw.tw_zone = -tb.timezone;
276 #endif /* defined(ZONEINFO) */
277 #endif /* defined(SYS5) */
278 tw.tw_flags &= ~TW_SDAY, tw.tw_flags |= TW_SEXP;
279 tw.tw_flags &= ~TW_SZONE, tw.tw_flags |= TW_SZEXP;
280 tw.tw_clock = *clock;
286 struct tws *dgmtime (clock)
287 register long *clock;
289 register struct tm *tm;
290 static struct tws tw;
294 tw.tw_flags = TW_NULL;
297 tw.tw_sec = tm -> tm_sec;
298 tw.tw_min = tm -> tm_min;
299 tw.tw_hour = tm -> tm_hour;
300 tw.tw_mday = tm -> tm_mday;
301 tw.tw_mon = tm -> tm_mon;
302 tw.tw_year = tm -> tm_year + CENTURY;
303 tw.tw_wday = tm -> tm_wday;
304 tw.tw_yday = tm -> tm_yday;
306 tw.tw_flags |= TW_DST;
308 tw.tw_flags &= ~TW_SDAY, tw.tw_flags |= TW_SEXP;
309 tw.tw_flags &= ~TW_SZONE, tw.tw_flags |= TW_SZEXP;
310 tw.tw_clock = *clock;
317 char *dasctime (tw, flags)
318 register struct tws *tw;
322 static char result[80];
327 /* Display timezone if known */
328 if ((tw->tw_flags & TW_SZONE) == TW_SZNIL)
331 (void) sprintf(result, " %s",
332 dtimezone(tw -> tw_zone, tw->tw_flags | flags));
333 (void) sprintf(buffer, "%02d %s %0*d %02d:%02d:%02d%s",
334 tw->tw_mday, tw_moty[tw->tw_mon],
335 tw -> tw_year < 100 ? 2 : 4, tw -> tw_year,
336 tw->tw_hour, tw->tw_min, tw->tw_sec, result);
338 if ((tw -> tw_flags & TW_SDAY) == TW_SEXP)
339 (void) sprintf (result, "%s, %s", tw_dotw[tw -> tw_wday], buffer);
341 if ((tw -> tw_flags & TW_SDAY) == TW_SNIL)
342 (void) strcpy (result, buffer);
344 (void) sprintf (result, "%s (%s)", buffer, tw_dotw[tw -> tw_wday]);
351 char *dtimezone (offset, flags)
357 register struct zone *z;
358 static char buffer[10];
361 mins = -((-offset) % 60);
362 hours = -((-offset) / 60);
369 if (!(flags & TW_ZONE) && mins == 0)
370 #if defined(SYS5) && defined(TZNAME)
373 return ((flags & TW_DST) ? tzname[1] : tzname[0]);
376 for (z = zones; z -> std; z++)
377 if (z -> shift == hours)
378 return (z -> dst && (flags & TW_DST) ? z -> dst : z -> std);
384 #endif /* defined(DSTXXX) */
385 (void) sprintf (buffer, "%s%02d%02d",
386 offset < 0 ? "-" : "+", abs (hours), abs (mins));
392 void twscopy (tb, tw)
393 register struct tws *tb,
397 tb -> tw_sec = tw -> tw_sec;
398 tb -> tw_min = tw -> tw_min;
399 tb -> tw_hour = tw -> tw_hour;
400 tb -> tw_mday = tw -> tw_mday;
401 tb -> tw_mon = tw -> tw_mon;
402 tb -> tw_year = tw -> tw_year;
403 tb -> tw_wday = tw -> tw_wday;
404 tb -> tw_yday = tw -> tw_yday;
405 tb -> tw_zone = tw -> tw_zone;
406 tb -> tw_clock = tw -> tw_clock;
407 tb -> tw_flags = tw -> tw_flags;
408 #else /* not notdef */
410 #endif /* not notdef */
414 int twsort (tw1, tw2)
415 register struct tws *tw1,
421 if (tw1 -> tw_clock == 0L)
422 (void) twclock (tw1);
423 if (tw2 -> tw_clock == 0L)
424 (void) twclock (tw2);
426 return ((c1 = tw1 -> tw_clock) > (c2 = tw2 -> tw_clock) ? 1
427 : c1 == c2 ? 0 : -1);
432 /* This routine is based on the gtime() routine written by Steven Shafer
433 (sas) at CMU. It was forwarded to MTR by Jay Lepreau at Utah-CS.
436 static int dmsize[] = {
437 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
442 register struct tws *tw;
451 register long result;
453 if (tw -> tw_clock != 0L)
454 return tw -> tw_clock;
456 if ((sec = tw -> tw_sec) < 0 || sec > 59
457 || (min = tw -> tw_min) < 0 || min > 59
458 || (hour = tw -> tw_hour) < 0 || hour > 23
459 || (mday = tw -> tw_mday) < 1 || mday > 31
460 || (mon = tw -> tw_mon + 1) < 1 || mon > 12)
461 return (tw -> tw_clock = -1L);
462 year = tw -> tw_year;
467 for (i = 1970; i < year; i++)
468 result += dysize (i);
469 if (dysize (year) == 366 && mon >= 3)
472 result += dmsize[mon - 1];
474 result = 24 * result + hour;
475 result = 60 * result + min;
476 result = 60 * result + sec;
477 result -= 60 * tw -> tw_zone;
478 if (tw -> tw_flags & TW_DST)
481 return (tw -> tw_clock = result);
487 * Simple calculation of day of the week. Algorithm used is Zeller's
488 * congruence. Currently, we assume if tw -> tw_year < 100
489 * then the century is CENTURY.
493 register struct tws *tw;
500 month = tw -> tw_mon - 1;
502 year = tw -> tw_year % 100;
503 century = tw -> tw_year >= 100 ? tw -> tw_year / 100 : (CENTURY / 100);
514 ((26 * month - 2) / 10 + day + year + year / 4
515 - 3 * century / 4 + 1) % 7;
517 tw -> tw_flags &= ~TW_SDAY, tw -> tw_flags |= TW_SIMP;
529 static char ident[] = "@@(#)$Id: dtime.c,v 1.13 1992/05/19 21:24:42 jromine Exp jromine $";
557 #endif defined(DSTXXX)
574 static char ident[] = "@@(#)$Id: dtime.c,v 1.12 1992/05/15 17:56:29 jromine Exp jromine $";
582 @fix problem with ZONEINFO on Suns.
587 static char ident[] = "@@(#)$Id: dtime.c,v 1.11 1992/02/07 00:45:31 jromine Exp jromine $";
600 static char ident[] = "@@(#)$Id: dtime.c,v 1.10 1992/02/07 00:27:17 jromine Exp jromine $";
604 #if defined(DSTXXX) && !defined(ZONEINFO)
607 #endif defined(DSTXXX) && !defined(ZONEINFO)
618 static char ident[] = "@@(#)$Id: dtime.c,v 1.9 1992/02/05 23:45:46 jromine Exp jromine $";
621 tw.tw_year = tm -> tm_year;
624 tw.tw_year = tm -> tm_year;
635 static char ident[] = "@@(#)$Id: dtime.c,v 1.8 1992/02/05 22:39:47 jromine Exp jromine $";
638 (void) sprintf(buffer, "%02d %s %04d %02d:%02d:%02d%s",
641 tw -> tw_year >= 100 ? tw -> tw_year : CENTURY + tw -> tw_year,
650 @start using 4 digit dates
655 static char ident[] = "@@(#)$Id: dtime.c,v 1.7 1990/04/09 13:23:19 sources Exp jromine $";
658 tw->tw_mday, tw_moty[tw->tw_mon], tw->tw_year,
664 @*** empty log message ***
669 static char ident[] = "@@(#)$Id: dtime.c,v 1.6 90/04/05 15:04:43 sources Exp Locker: sources $";
675 tw -> tw_year >= 100 ? tw -> tw_year : 1900 + tw -> tw_year);
678 (void) sprintf(buffer, "%02d %s %02d %02d:%02d:%02d%s",
684 century = tw -> tw_year >= 100 ? tw -> tw_year / 100 : CENTURY;
695 static char ident[] = "@@(#)$Id:$";
705 #include <sys/time.h>
719 tw.tw_zone = -(timezone / 60);
732 @ignore military timezones per RFC1123
741 @Fixes from Van Jacobson
758 static char buffer[80],
762 (void) sprintf (buffer, "%02d %s %02d %02d:%02d:%02d %s",
763 tw -> tw_mday, tw_moty[tw -> tw_mon], tw -> tw_year,
764 tw -> tw_hour, tw -> tw_min, tw -> tw_sec,
765 dtimezone (tw -> tw_zone, tw -> tw_flags | flags));