1994-09-29 23:04:24 +00:00
|
|
|
/*
|
1993-12-21 18:36:48 +00:00
|
|
|
* calleapwhen - determine the number of seconds to the next possible
|
|
|
|
* leap occurance and the last one.
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "ntp_types.h"
|
|
|
|
#include "ntp_calendar.h"
|
|
|
|
#include "ntp_stdlib.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* calleaptab - leaps occur at the end of December and June
|
|
|
|
*/
|
1994-09-29 23:04:24 +00:00
|
|
|
long calleaptab[10] = {
|
1993-12-21 18:36:48 +00:00
|
|
|
-(JAN+FEBLEAP)*SECSPERDAY, /* leap previous to cycle */
|
|
|
|
(MAR+APR+MAY+JUN)*SECSPERDAY, /* end of June */
|
|
|
|
(MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC)*SECSPERDAY, /* end of Dec */
|
|
|
|
(MAR+APR+MAY+JUN)*SECSPERDAY + SECSPERYEAR,
|
|
|
|
(MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC)*SECSPERDAY + SECSPERYEAR,
|
|
|
|
(MAR+APR+MAY+JUN)*SECSPERDAY + 2*SECSPERYEAR,
|
|
|
|
(MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC)*SECSPERDAY + 2*SECSPERYEAR,
|
|
|
|
(MAR+APR+MAY+JUN)*SECSPERDAY + 3*SECSPERYEAR,
|
|
|
|
(MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC)*SECSPERDAY + 3*SECSPERYEAR,
|
|
|
|
(MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC+JAN+FEBLEAP+MAR+APR+MAY+JUN)
|
|
|
|
*SECSPERDAY + 3*SECSPERYEAR, /* next after current cycle */
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
calleapwhen(ntpdate, leaplast, leapnext)
|
1994-09-29 23:04:24 +00:00
|
|
|
u_long ntpdate;
|
|
|
|
u_long *leaplast;
|
|
|
|
u_long *leapnext;
|
1993-12-21 18:36:48 +00:00
|
|
|
{
|
1994-09-29 23:04:24 +00:00
|
|
|
register u_long dateincycle;
|
1993-12-21 18:36:48 +00:00
|
|
|
register int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the offset from the start of the cycle
|
|
|
|
*/
|
|
|
|
dateincycle = ntpdate;
|
|
|
|
if (dateincycle >= MAR1988)
|
|
|
|
dateincycle -= MAR1988;
|
|
|
|
else
|
|
|
|
dateincycle -= MAR1900;
|
|
|
|
|
|
|
|
while (dateincycle >= SECSPERCYCLE)
|
|
|
|
dateincycle -= SECSPERCYCLE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find where we are with respect to the leap events.
|
|
|
|
*/
|
|
|
|
for (i = 1; i < 9; i++)
|
1994-09-29 23:04:24 +00:00
|
|
|
if (dateincycle < (u_long)calleaptab[i])
|
1993-12-21 18:36:48 +00:00
|
|
|
break;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1993-12-21 18:36:48 +00:00
|
|
|
/*
|
|
|
|
* i points at the next leap. Compute the last and the next.
|
|
|
|
*/
|
1994-09-29 23:04:24 +00:00
|
|
|
*leaplast = (u_long)((long)dateincycle - calleaptab[i-1]);
|
|
|
|
*leapnext = (u_long)(calleaptab[i] - (long)dateincycle);
|
1993-12-21 18:36:48 +00:00
|
|
|
}
|