154359Sroberto/*
254359Sroberto * caljulian - determine the Julian date from an NTP time.
3285612Sdelphij *
4285612Sdelphij * (Note: since we use the GREGORIAN calendar, this should be renamed to
5285612Sdelphij * 'calgregorian' eventually...)
654359Sroberto */
7285612Sdelphij#include <config.h>
854359Sroberto#include <sys/types.h>
954359Sroberto
1054359Sroberto#include "ntp_types.h"
1154359Sroberto#include "ntp_calendar.h"
1254359Sroberto
13285612Sdelphij#if !(defined(ISC_CHECK_ALL) || defined(ISC_CHECK_NONE) || \
14285612Sdelphij      defined(ISC_CHECK_ENSURE) || defined(ISC_CHECK_INSIST) || \
15285612Sdelphij      defined(ISC_CHECK_INVARIANT))
16285612Sdelphij# define ISC_CHECK_ALL
17285612Sdelphij#endif
1854359Sroberto
19285612Sdelphij#include "ntp_assert.h"
20285612Sdelphij
2154359Srobertovoid
2254359Srobertocaljulian(
23285612Sdelphij	uint32_t		ntp,
24285612Sdelphij	struct calendar *	jt
2554359Sroberto	)
2654359Sroberto{
27285612Sdelphij	vint64		vlong;
28285612Sdelphij	ntpcal_split	split;
29285612Sdelphij
30285612Sdelphij
31289997Sglebius	INSIST(NULL != jt);
3254359Sroberto
3354359Sroberto	/*
34285612Sdelphij	 * Unfold ntp time around current time into NTP domain. Split
35285612Sdelphij	 * into days and seconds, shift days into CE domain and
36285612Sdelphij	 * process the parts.
3754359Sroberto	 */
38285612Sdelphij	vlong = ntpcal_ntp_to_ntp(ntp, NULL);
39285612Sdelphij	split = ntpcal_daysplit(&vlong);
40285612Sdelphij	ntpcal_daysplit_to_date(jt, &split, DAY_NTP_STARTS);
4154359Sroberto}
42