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