* Copyright (c) 1983 Eric P. Allman
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)arpadate.c 8.1 (Berkeley) %G%";
** ARPADATE -- Create date in ARPANET format
** ud -- unix style date string. if NULL, one is created.
** pointer to an ARPANET date field
** date is stored in a local buffer -- subsequent
** Timezone is computed from local time, rather than
** from whereever (and whenever) the message was sent.
** To do better is very hard.
** Some sites are now inserting the timezone into the
** local date. This routine should figure out what
** the format is and work appropriately.
** This will be used if a null argument is passed and
** to resolve the timezone.
** Crack the UNIX date line in a singularly unoriginal way.
p
= &ud
[11]; /* 01:03:52 */
* should really get the timezone from the time in "ud" (which
* is only different if a non-null arg was passed which is different
* from the current time), but for all practical purposes, returning
* the current local zone will do (its all that is ever needed).
off
= (lt
->tm_hour
- gmt
.tm_hour
) * 60 + lt
->tm_min
- gmt
.tm_min
;
/* assume that offset isn't more than a day ... */
if (lt
->tm_year
< gmt
.tm_year
)
else if (lt
->tm_year
> gmt
.tm_year
)
else if (lt
->tm_yday
< gmt
.tm_yday
)
else if (lt
->tm_yday
> gmt
.tm_yday
)
if (off
>= 24*60) /* should be impossible */
off
= 23*60+59; /* if not, insert silly value */
*q
++ = (off
/ 600) + '0';
*q
++ = (off
/ 60) % 10 + '0';