2 * Copyright (c) 1998 Sendmail, Inc. All rights reserved.
3 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * By using this file, you agree to the terms and conditions set
8 * forth in the LICENSE file which can be found at the top level of
9 * the sendmail distribution.
14 static char sccsid[] = "@(#)arpadate.c 8.14 (Berkeley) 2/2/1999";
17 # include "sendmail.h"
20 ** ARPADATE -- Create date in ARPANET format
23 ** ud -- unix style date string. if NULL, one is created.
26 ** pointer to an ARPANET date field
32 ** date is stored in a local buffer -- subsequent
33 ** calls will overwrite.
36 ** Timezone is computed from local time, rather than
37 ** from whereever (and whenever) the message was sent.
38 ** To do better is very hard.
40 ** Some sites are now inserting the timezone into the
41 ** local date. This routine should figure out what
42 ** the format is and work appropriately.
46 # define TZNAME_MAX 50 /* max size of timezone */
49 /* values for TZ_TYPE */
50 #define TZ_NONE 0 /* no character timezone support */
51 #define TZ_TM_NAME 1 /* use tm->tm_name */
52 #define TZ_TM_ZONE 2 /* use tm->tm_zone */
53 #define TZ_TZNAME 3 /* use tzname[] */
54 #define TZ_TIMEZONE 4 /* use timezone() */
64 register struct tm *lt;
68 static char b[43 + TZNAME_MAX];
72 ** This will be used if a null argument is passed and
73 ** to resolve the timezone.
81 ** Crack the UNIX date line in a singularly unoriginal way.
101 p = &ud[4]; /* Sep */
107 p = &ud[20]; /* 1979 */
114 p = &ud[11]; /* 01:03:52 */
115 for (i = 8; i > 0; i--)
119 * should really get the timezone from the time in "ud" (which
120 * is only different if a non-null arg was passed which is different
121 * from the current time), but for all practical purposes, returning
122 * the current local zone will do (its all that is ever needed).
127 off = (lt->tm_hour - gmt.tm_hour) * 60 + lt->tm_min - gmt.tm_min;
129 /* assume that offset isn't more than a day ... */
130 if (lt->tm_year < gmt.tm_year)
132 else if (lt->tm_year > gmt.tm_year)
134 else if (lt->tm_yday < gmt.tm_yday)
136 else if (lt->tm_yday > gmt.tm_yday)
149 #if TZ_TYPE == TZ_TM_NAME
152 #if TZ_TYPE == TZ_TM_ZONE
155 #if TZ_TYPE == TZ_TZNAME
157 extern char *tzname[];
159 if (lt->tm_isdst > 0)
161 else if (lt->tm_isdst == 0)
167 #if TZ_TYPE == TZ_TIMEZONE
169 extern char *timezone();
171 tz = timezone(off, lt->tm_isdst);
182 if (off >= 24*60) /* should be impossible */
183 off = 23*60+59; /* if not, insert silly value */
185 *q++ = (off / 600) + '0';
186 *q++ = (off / 60) % 10 + '0';
188 *q++ = (off / 10) + '0';
189 *q++ = (off % 10) + '0';
190 if (tz != NULL && *tz != '\0')
194 while (*tz != '\0' && q < &b[sizeof b - 3])