1999-07-03 16:30:16 +04:00
|
|
|
/* $NetBSD: caltontp.c,v 1.5 1999/07/03 12:30:29 simonb Exp $ */
|
1998-01-09 06:15:09 +03:00
|
|
|
|
1997-04-18 17:22:49 +04:00
|
|
|
/*
|
1998-03-06 21:17:13 +03:00
|
|
|
* caltontp - convert a date to an NTP time
|
1997-04-18 17:22:49 +04:00
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "ntp_types.h"
|
|
|
|
#include "ntp_calendar.h"
|
|
|
|
#include "ntp_stdlib.h"
|
|
|
|
|
|
|
|
u_long
|
|
|
|
caltontp(jt)
|
|
|
|
register const struct calendar *jt;
|
|
|
|
{
|
1998-03-06 21:17:13 +03:00
|
|
|
u_long ace_days; /* absolute Christian Era days */
|
|
|
|
u_long ntp_days;
|
|
|
|
int prior_years;
|
|
|
|
u_long ntp_time;
|
1999-07-03 16:30:16 +04:00
|
|
|
|
1998-03-06 21:17:13 +03:00
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*/
|
1999-07-03 16:30:16 +04:00
|
|
|
ntp_time =
|
1998-03-06 21:17:13 +03:00
|
|
|
ntp_days*SECSPERDAY+SECSPERMIN*(MINSPERHR*jt->hour + jt->minute);
|
|
|
|
|
|
|
|
return ntp_time;
|
1997-04-18 17:22:49 +04:00
|
|
|
}
|