File: caltontp.c

package info (click to toggle)
ntp 1%3A4.2.2.p4%2Bdfsg-2etch4
  • links: PTS
  • area: main
  • in suites: etch
  • size: 10,236 kB
  • ctags: 10,865
  • sloc: ansic: 90,242; sh: 4,314; perl: 1,331; makefile: 631; awk: 417; asm: 37; sed: 7
file content (42 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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;
}