154359Sroberto/*
254359Sroberto * caljulian - determine the Julian date from an NTP time.
3280849Scy *
4280849Scy * (Note: since we use the GREGORIAN calendar, this should be renamed to
5280849Scy * 'calgregorian' eventually...)
654359Sroberto */
7280849Scy#include <config.h>
854359Sroberto#include <sys/types.h>
954359Sroberto
1054359Sroberto#include "ntp_types.h"
1154359Sroberto#include "ntp_calendar.h"
1254359Sroberto
13280849Scy#if !(defined(ISC_CHECK_ALL) || defined(ISC_CHECK_NONE) || \
14280849Scy      defined(ISC_CHECK_ENSURE) || defined(ISC_CHECK_INSIST) || \
15280849Scy      defined(ISC_CHECK_INVARIANT))
16280849Scy# define ISC_CHECK_ALL
17280849Scy#endif
1854359Sroberto
19280849Scy#include "ntp_assert.h"
20280849Scy
2154359Srobertovoid
2254359Srobertocaljulian(
23280849Scy	uint32_t		ntp,
24280849Scy	struct calendar *	jt
2554359Sroberto	)
2654359Sroberto{
27280849Scy	vint64		vlong;
28280849Scy	ntpcal_split	split;
29280849Scy
30280849Scy
31289764Sglebius	INSIST(NULL != jt);
3254359Sroberto
3354359Sroberto	/*
34280849Scy	 * Unfold ntp time around current time into NTP domain. Split
35280849Scy	 * into days and seconds, shift days into CE domain and
36280849Scy	 * process the parts.
3754359Sroberto	 */
38280849Scy	vlong = ntpcal_ntp_to_ntp(ntp, NULL);
39280849Scy	split = ntpcal_daysplit(&vlong);
40280849Scy	ntpcal_daysplit_to_date(jt, &split, DAY_NTP_STARTS);
4154359Sroberto}
42