2 * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
16 SM_RCSID("@(#)$Id: arpadate.c,v 8.31 2006/08/15 23:24:55 ca Exp $")
19 ** ARPADATE -- Create date in ARPANET format
22 ** ud -- unix style date string. if NULL, one is created.
25 ** pointer to an ARPANET date field
31 ** date is stored in a local buffer -- subsequent
32 ** calls will overwrite.
35 ** Timezone is computed from local time, rather than
36 ** from wherever (and whenever) the message was sent.
37 ** To do better is very hard.
39 ** Some sites are now inserting the timezone into the
40 ** local date. This routine should figure out what
41 ** the format is and work appropriately.
45 # define TZNAME_MAX 50 /* max size of timezone */
46 #endif /* ! TZNAME_MAX */
48 /* values for TZ_TYPE */
49 #define TZ_NONE 0 /* no character timezone support */
50 #define TZ_TM_NAME 1 /* use tm->tm_name */
51 #define TZ_TM_ZONE 2 /* use tm->tm_zone */
52 #define TZ_TZNAME 3 /* use tzname[] */
53 #define TZ_TIMEZONE 4 /* use timezone() */
63 register struct tm
*lt
;
67 static char b
[43 + TZNAME_MAX
];
71 ** This will be used if a null argument is passed and
72 ** to resolve the timezone.
75 /* SM_REQUIRE(ud == NULL || strlen(ud) >= 23); */
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).
128 off
= (lt
->tm_hour
- gmt
.tm_hour
) * 60 + lt
->tm_min
- gmt
.tm_min
;
130 /* assume that offset isn't more than a day ... */
131 if (lt
->tm_year
< gmt
.tm_year
)
133 else if (lt
->tm_year
> gmt
.tm_year
)
135 else if (lt
->tm_yday
< gmt
.tm_yday
)
137 else if (lt
->tm_yday
> gmt
.tm_yday
)
150 #if TZ_TYPE == TZ_TM_NAME
152 #endif /* TZ_TYPE == TZ_TM_NAME */
153 #if TZ_TYPE == TZ_TM_ZONE
155 #endif /* TZ_TYPE == TZ_TM_ZONE */
156 #if TZ_TYPE == TZ_TZNAME
158 extern char *tzname
[];
160 if (lt
->tm_isdst
> 0)
162 else if (lt
->tm_isdst
== 0)
167 #endif /* TZ_TYPE == TZ_TZNAME */
168 #if TZ_TYPE == TZ_TIMEZONE
170 extern char *timezone();
172 tz
= timezone(off
, lt
->tm_isdst
);
174 #endif /* TZ_TYPE == TZ_TIMEZONE */
183 if (off
>= 24*60) /* should be impossible */
184 off
= 23*60+59; /* if not, insert silly value */
186 *q
++ = (off
/ 600) + '0';
187 *q
++ = (off
/ 60) % 10 + '0';
189 *q
++ = (off
/ 10) + '0';
190 *q
++ = (off
% 10) + '0';
191 if (tz
!= NULL
&& *tz
!= '\0')
195 while (*tz
!= '\0' && q
< &b
[sizeof(b
) - 3])