diff options
author | roberto <roberto@FreeBSD.org> | 1999-12-09 13:01:21 +0000 |
---|---|---|
committer | roberto <roberto@FreeBSD.org> | 1999-12-09 13:01:21 +0000 |
commit | ef64b99e8412f2273dd2e8b3291c2f78ffc4667f (patch) | |
tree | fc0cfa1aab0ff6b228f511b410733ef4f35d1ead /contrib/ntp/libntp/caltontp.c | |
download | FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.zip FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.tar.gz |
Virgin import of ntpd 4.0.98f
Diffstat (limited to 'contrib/ntp/libntp/caltontp.c')
-rw-r--r-- | contrib/ntp/libntp/caltontp.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/contrib/ntp/libntp/caltontp.c b/contrib/ntp/libntp/caltontp.c new file mode 100644 index 0000000..9ec1064 --- /dev/null +++ b/contrib/ntp/libntp/caltontp.c @@ -0,0 +1,42 @@ +/* + * caltontp - convert a date to an NTP time + */ +#include <sys/types.h> + +#include "ntp_types.h" +#include "ntp_calendar.h" +#include "ntp_stdlib.h" + +u_long +caltontp( + register const struct calendar *jt + ) +{ + u_long ace_days; /* absolute Christian Era days */ + u_long ntp_days; + int prior_years; + u_long ntp_time; + + /* + * First convert today's date to absolute days past 12/1/1 BC + */ + prior_years = jt->year-1; + ace_days = jt->yearday /* days this year */ + +(DAYSPERYEAR*prior_years) /* plus days in previous years */ + +(prior_years/4) /* plus prior years's leap days */ + -(prior_years/100) /* minus leapless century years */ + +(prior_years/400); /* plus leapful Gregorian yrs */ + + /* + * Subtract out 1/1/1900, the beginning of the NTP epoch + */ + ntp_days = ace_days - DAY_NTP_STARTS; + + /* + * Do the obvious: + */ + ntp_time = + ntp_days*SECSPERDAY+SECSPERMIN*(MINSPERHR*jt->hour + jt->minute); + + return ntp_time; +} |