154359Sroberto/*
254359Sroberto * caltontp - convert a date to an NTP time
354359Sroberto */
454359Sroberto#include <sys/types.h>
554359Sroberto
654359Sroberto#include "ntp_types.h"
754359Sroberto#include "ntp_calendar.h"
854359Sroberto#include "ntp_stdlib.h"
954359Sroberto
1054359Srobertou_long
1154359Srobertocaltontp(
1254359Sroberto	register const struct calendar *jt
1354359Sroberto	)
1454359Sroberto{
1554359Sroberto    u_long ace_days;			     /* absolute Christian Era days */
1654359Sroberto    u_long ntp_days;
1754359Sroberto    int    prior_years;
1854359Sroberto    u_long ntp_time;
1954359Sroberto
2054359Sroberto    /*
2154359Sroberto     * First convert today's date to absolute days past 12/1/1 BC
2254359Sroberto     */
2354359Sroberto    prior_years = jt->year-1;
2454359Sroberto    ace_days = jt->yearday		     /* days this year */
2554359Sroberto	+(DAYSPERYEAR*prior_years)	     /* plus days in previous years */
2654359Sroberto	+(prior_years/4)		     /* plus prior years's leap days */
2754359Sroberto	-(prior_years/100)		     /* minus leapless century years */
2854359Sroberto	+(prior_years/400);		     /* plus leapful Gregorian yrs */
2954359Sroberto
3054359Sroberto    /*
3154359Sroberto     * Subtract out 1/1/1900, the beginning of the NTP epoch
3254359Sroberto     */
3354359Sroberto    ntp_days = ace_days - DAY_NTP_STARTS;
3454359Sroberto
3554359Sroberto    /*
3654359Sroberto     * Do the obvious:
3754359Sroberto     */
3854359Sroberto    ntp_time =
3954359Sroberto	ntp_days*SECSPERDAY+SECSPERMIN*(MINSPERHR*jt->hour + jt->minute);
4054359Sroberto
4154359Sroberto    return ntp_time;
4254359Sroberto}
43