xref: /freebsd/contrib/ntp/libntp/caljulian.c (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 /*
2  * caljulian - determine the Julian date from an NTP time.
3  *
4  * (Note: since we use the GREGORIAN calendar, this should be renamed to
5  * 'calgregorian' eventually...)
6  */
7 #include <config.h>
8 #include <sys/types.h>
9 
10 #include "ntp_types.h"
11 #include "ntp_calendar.h"
12 
13 #if !(defined(ISC_CHECK_ALL) || defined(ISC_CHECK_NONE) || \
14       defined(ISC_CHECK_ENSURE) || defined(ISC_CHECK_INSIST) || \
15       defined(ISC_CHECK_INVARIANT))
16 # define ISC_CHECK_ALL
17 #endif
18 
19 #include "ntp_assert.h"
20 
21 void
22 caljulian(
23 	uint32_t		ntp,
24 	struct calendar *	jt
25 	)
26 {
27 	vint64		vlong;
28 	ntpcal_split	split;
29 
30 
31 	INSIST(NULL != jt);
32 
33 	/*
34 	 * Unfold ntp time around current time into NTP domain. Split
35 	 * into days and seconds, shift days into CE domain and
36 	 * process the parts.
37 	 */
38 	vlong = ntpcal_ntp_to_ntp(ntp, NULL);
39 	split = ntpcal_daysplit(&vlong);
40 	ntpcal_daysplit_to_date(jt, &split, DAY_NTP_STARTS);
41 }
42