uint32_t caltontp( const struct calendar *jt ) { int32_t eraday; /* CE Rata Die number */ vint64 ntptime;/* resulting NTP time */ NTP_INSIST(jt != NULL); NTP_REQUIRE(jt->month <= 13); /* permit month 0..13! */ NTP_REQUIRE(jt->monthday <= 32); NTP_REQUIRE(jt->yearday <= 366); NTP_REQUIRE(jt->hour <= 24); NTP_REQUIRE(jt->minute <= MINSPERHR); NTP_REQUIRE(jt->second <= SECSPERMIN); /* * First convert the date to he corresponding RataDie * number. If yearday is not zero, assume that it contains a * useable value and avoid all calculations involving month * and day-of-month. Do a full evaluation otherwise. */ if (jt->yearday) eraday = ntpcal_year_to_ystart(jt->year) + jt->yearday - 1; else eraday = ntpcal_date_to_rd(jt); ntptime = ntpcal_dayjoin(eraday - DAY_NTP_STARTS, ntpcal_etime_to_seconds(jt->hour, jt->minute, jt->second)); return ntptime.d_s.lo; }
void ntpdtest::settime(int y, int m, int d, int H, int M, int S) { time_t days(ntpcal_edate_to_eradays(y-1, m-1, d-1) + 1 - DAY_UNIX_STARTS); time_t secs(ntpcal_etime_to_seconds(H, M, S)); nowtime = days * SECSPERDAY + secs; }