xref: /freebsd/contrib/ntp/libntp/caljulian.c (revision b626f5a73a48f44a31a200291b141e1da408a2ff)
1c0b746e5SOllivier Robert /*
2c0b746e5SOllivier Robert  * caljulian - determine the Julian date from an NTP time.
32b15cb3dSCy Schubert  *
42b15cb3dSCy Schubert  * (Note: since we use the GREGORIAN calendar, this should be renamed to
52b15cb3dSCy Schubert  * 'calgregorian' eventually...)
6c0b746e5SOllivier Robert  */
72b15cb3dSCy Schubert #include <config.h>
8c0b746e5SOllivier Robert #include <sys/types.h>
9c0b746e5SOllivier Robert 
10c0b746e5SOllivier Robert #include "ntp_types.h"
11c0b746e5SOllivier Robert #include "ntp_calendar.h"
12c0b746e5SOllivier Robert 
132b15cb3dSCy Schubert #if !(defined(ISC_CHECK_ALL) || defined(ISC_CHECK_NONE) || \
142b15cb3dSCy Schubert       defined(ISC_CHECK_ENSURE) || defined(ISC_CHECK_INSIST) || \
152b15cb3dSCy Schubert       defined(ISC_CHECK_INVARIANT))
162b15cb3dSCy Schubert # define ISC_CHECK_ALL
17ea906c41SOllivier Robert #endif
182b15cb3dSCy Schubert 
192b15cb3dSCy Schubert #include "ntp_assert.h"
202b15cb3dSCy Schubert 
212b15cb3dSCy Schubert void
caljulian(uint32_t ntp,struct calendar * jt)222b15cb3dSCy Schubert caljulian(
232b15cb3dSCy Schubert 	uint32_t		ntp,
242b15cb3dSCy Schubert 	struct calendar *	jt
252b15cb3dSCy Schubert 	)
262b15cb3dSCy Schubert {
272b15cb3dSCy Schubert 	vint64		vlong;
282b15cb3dSCy Schubert 	ntpcal_split	split;
292b15cb3dSCy Schubert 
302b15cb3dSCy Schubert 
31*9034852cSGleb Smirnoff 	INSIST(NULL != jt);
322b15cb3dSCy Schubert 
332b15cb3dSCy Schubert 	/*
342b15cb3dSCy Schubert 	 * Unfold ntp time around current time into NTP domain. Split
352b15cb3dSCy Schubert 	 * into days and seconds, shift days into CE domain and
362b15cb3dSCy Schubert 	 * process the parts.
372b15cb3dSCy Schubert 	 */
382b15cb3dSCy Schubert 	vlong = ntpcal_ntp_to_ntp(ntp, NULL);
392b15cb3dSCy Schubert 	split = ntpcal_daysplit(&vlong);
402b15cb3dSCy Schubert 	ntpcal_daysplit_to_date(jt, &split, DAY_NTP_STARTS);
412b15cb3dSCy Schubert }
42