/* This code placed in the public domain by Mark W. Eichin */
#include <stdio.h>
#include "autoconf.h"
#ifdef HAVE_SYS_TYPES_H
#endif
#ifdef HAVE_SYS_TIME_H
#ifdef TIME_WITH_SYS_TIME
#include <time.h>
#endif
#else
#include <time.h>
#endif
/* take a struct tm, return seconds from GMT epoch */
/* like mktime, this ignores tm_wday and tm_yday. */
/* unlike mktime, this does not set them... it only passes a return value. */
0, /* jan 31 */
31, /* feb 28 */
59, /* mar 31 */
90, /* apr 30 */
120, /* may 31 */
151, /* jun 30 */
181, /* jul 31 */
212, /* aug 31 */
243, /* sep 30 */
273, /* oct 31 */
304, /* nov 30 */
334 /* dec 31 */
};
{
/*
* For 32-bit signed time_t centered on 1/1/1970, the range is:
* time 0x80000000 -> Fri Dec 13 16:45:52 1901
* time 0x7fffffff -> Mon Jan 18 22:14:07 2038
*
* So years 1901 and 2038 are allowable, but we can't encode all
* checking for such cases.
*/
assert_time(t->tm_mon>=0);
assert_time(t->tm_hour>=0);
assert_time(t->tm_min>=0);
assert_time(t->tm_sec>=0);
/* add in leap day for all previous years */
if (t->tm_year >= 70)
else
/* add in leap day for this year */
return accum;
}
#ifdef TEST_LEAP
int
{
int yr;
time_t t;
};
{
t = gmt_mktime (&tm);
if (t == (time_t) -1)
printf ("-1\n");
else
{
long u;
if (t % (24 * 60 * 60))
printf ("(not integral multiple of days) ");
u = t / (24 * 60 * 60);
printf ("%3ld*365%+ld\t0x%08lx\n",
(long) (u / 365), (long) (u % 365),
(long) t);
}
}
return 0;
}
#endif