]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ntp/libntp/caltontp.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ntp / libntp / caltontp.c
1 /*
2  * caltontp - convert a date to an NTP time
3  */
4 #include <sys/types.h>
5
6 #include "ntp_types.h"
7 #include "ntp_calendar.h"
8 #include "ntp_stdlib.h"
9
10 u_long
11 caltontp(
12         register const struct calendar *jt
13         )
14 {
15     u_long ace_days;                         /* absolute Christian Era days */
16     u_long ntp_days;
17     int    prior_years;
18     u_long ntp_time;
19     
20     /*
21      * First convert today's date to absolute days past 12/1/1 BC
22      */
23     prior_years = jt->year-1;
24     ace_days = jt->yearday                   /* days this year */
25         +(DAYSPERYEAR*prior_years)           /* plus days in previous years */
26         +(prior_years/4)                     /* plus prior years's leap days */
27         -(prior_years/100)                   /* minus leapless century years */
28         +(prior_years/400);                  /* plus leapful Gregorian yrs */
29
30     /*
31      * Subtract out 1/1/1900, the beginning of the NTP epoch
32      */
33     ntp_days = ace_days - DAY_NTP_STARTS;
34
35     /*
36      * Do the obvious:
37      */
38     ntp_time = 
39         ntp_days*SECSPERDAY+SECSPERMIN*(MINSPERHR*jt->hour + jt->minute);
40
41     return ntp_time;
42 }