1 # include "conf.h" 2 # include <sys/time.h> 3 # ifndef V6 4 # include <sys/types.h> 5 # include <sys/timeb.h> 6 # endif 7 # include "useful.h" 8 9 SCCSID(@(#)arpadate.c 4.1 07/25/83); 10 11 /* 12 ** ARPADATE -- Create date in ARPANET format 13 ** 14 ** Parameters: 15 ** ud -- unix style date string. if NULL, one is created. 16 ** 17 ** Returns: 18 ** pointer to an ARPANET date field 19 ** 20 ** Side Effects: 21 ** none 22 ** 23 ** WARNING: 24 ** date is stored in a local buffer -- subsequent 25 ** calls will overwrite. 26 ** 27 ** Bugs: 28 ** Timezone is computed from local time, rather than 29 ** from whereever (and whenever) the message was sent. 30 ** To do better is very hard. 31 ** 32 ** Some sites are now inserting the timezone into the 33 ** local date. This routine should figure out what 34 ** the format is and work appropriately. 35 */ 36 37 char * 38 arpadate(ud) 39 register char *ud; 40 { 41 register char *p; 42 register char *q; 43 static char b[40]; 44 extern char *ctime(); 45 register int i; 46 extern struct tm *localtime(); 47 # ifdef V6 48 long t; 49 extern char *StdTimezone, *DstTimezone; 50 extern long time(); 51 # else 52 struct timeb t; 53 extern struct timeb *ftime(); 54 extern char *timezone(); 55 # endif 56 57 /* 58 ** Get current time. 59 ** This will be used if a null argument is passed and 60 ** to resolve the timezone. 61 */ 62 63 # ifdef V6 64 (void) time(&t); 65 if (ud == NULL) 66 ud = ctime(&t); 67 # else 68 ftime(&t); 69 if (ud == NULL) 70 ud = ctime(&t.time); 71 # endif 72 73 /* 74 ** Crack the UNIX date line in a singularly unoriginal way. 75 */ 76 77 q = b; 78 79 p = &ud[0]; /* Mon */ 80 *q++ = *p++; 81 *q++ = *p++; 82 *q++ = *p++; 83 *q++ = ','; 84 *q++ = ' '; 85 86 p = &ud[8]; /* 16 */ 87 if (*p == ' ') 88 p++; 89 else 90 *q++ = *p++; 91 *q++ = *p++; 92 *q++ = ' '; 93 94 p = &ud[4]; /* Sep */ 95 *q++ = *p++; 96 *q++ = *p++; 97 *q++ = *p++; 98 *q++ = ' '; 99 100 p = &ud[22]; /* 79 */ 101 *q++ = *p++; 102 *q++ = *p++; 103 *q++ = ' '; 104 105 p = &ud[11]; /* 01:03:52 */ 106 for (i = 8; i > 0; i--) 107 *q++ = *p++; 108 109 /* -PST or -PDT */ 110 # ifdef V6 111 if (localtime(&t)->tm_isdst) 112 p = DstTimezone; 113 else 114 p = StdTimezone; 115 # else 116 p = timezone(t.timezone, localtime(&t.time)->tm_isdst); 117 # endif V6 118 if (p[3] != '\0') 119 { 120 /* hours from GMT */ 121 p += 3; 122 *q++ = *p++; 123 if (p[1] == ':') 124 *q++ = '0'; 125 else 126 *q++ = *p++; 127 *q++ = *p++; 128 p++; /* skip ``:'' */ 129 *q++ = *p++; 130 *q++ = *p++; 131 } 132 else 133 { 134 *q++ = ' '; 135 *q++ = *p++; 136 *q++ = *p++; 137 *q++ = *p++; 138 } 139 140 *q = '\0'; 141 return (b); 142 } 143