#include "ntp_fp.h"
#include "ntp_unixtime.h"
#include "ntp_stdlib.h"
#define MULBY10(x) (((x)<<3) + ((x)<<1))
#define MULBY60(x) (((x)<<6) - ((x)<<2))
#define MULBY24(x) (((x)<<4) + ((x)<<3))
#define TWODAYS (2*24*60*60)
#define CLOSETIME (4*60*60)
int
clocktime(
int yday,
int hour,
int minute,
int second,
int tzoff,
u_long rec_ui,
u_long *yearstart,
u_int32 *ts_ui
)
{
register long tmp;
register u_long date;
register u_long yst;
tmp = (long)(MULBY24((yday-1)) + hour + tzoff);
tmp = MULBY60(tmp) + (long)minute;
tmp = MULBY60(tmp) + (long)second;
yst = *yearstart;
if (yst == 0) {
yst = calyearstart(rec_ui);
*yearstart = yst;
}
date = (u_long)(tmp + (long)yst);
if (date < (rec_ui + CLOSETIME) &&
date > (rec_ui - CLOSETIME)) {
*ts_ui = date;
return 1;
}
yst = calyearstart(rec_ui);
if (yst != *yearstart) {
date = (u_long)((long)yst + tmp);
*ts_ui = date;
if (date < (rec_ui + CLOSETIME) &&
date > (rec_ui - CLOSETIME)) {
*yearstart = yst;
return 1;
}
}
if ((rec_ui - yst) < TWODAYS) {
yst = calyearstart(yst - TWODAYS);
if (yst != *yearstart) {
date = (u_long)(tmp + (long)yst);
if (date < (rec_ui + CLOSETIME) &&
date > (rec_ui - CLOSETIME)) {
*yearstart = yst;
*ts_ui = date;
return 1;
}
}
}
yst = calyearstart(rec_ui + TWODAYS);
if (yst != *yearstart) {
date = (u_long)((long)yst + tmp);
if (date < (rec_ui + CLOSETIME) &&
date > (rec_ui - CLOSETIME)) {
*yearstart = yst;
*ts_ui = date;
return 1;
}
}
return 0;
}