FreeBSD/contrib/ntp/libntp/ntp_calendar.c
/*
 * Given a second in the NTP time scale and a pivot, expand the NTP
 * time stamp around the pivot and convert into an ISO calendar time
 * stamp.
 */
Given a second in the NTP time scale and a pivot, expand the NTP
time stamp around the pivot and convert into an ISO calendar time
stamp.
Given a second in the NTP time scale and a pivot expand the NTP time stamp around the pivot and convert into an ISO calendar time stamp .
int
isocal_ntp64_to_date(
	struct isodate *id,
	const vint64   *ntp
	)
{
	ntpcal_split ds;
	int32_t      ts[3];
	uint32_t     uw, ud, sflag;
	ds = ntpcal_daysplit(ntp);
	ds.hi += priv_timesplit(ts, ds.lo);
	id->hour   = (uint8_t)ts[0];
	id->minute = (uint8_t)ts[1];
	id->second = (uint8_t)ts[2];
	ds.hi += DAY_NTP_STARTS - 1; 
	sflag = int32_sflag(ds.hi);
	ud  = int32_to_uint32_2cpl(ds.hi);
	uw  = sflag ^ ((sflag ^ ud) / DAYSPERWEEK);
	ud -= uw * DAYSPERWEEK;
	ds.hi = uint32_2cpl_to_int32(uw);
	ds.lo = ud;
	id->weekday = (uint8_t)ds.lo + 1;	
	ds = isocal_split_eraweeks(ds.hi);	
	id->year = (uint16_t)ds.hi + 1;		
	id->week = (uint8_t )ds.lo + 1;
	return (ds.hi >= 0 && ds.hi < 0x0000FFFF);
}
int isocal_ntp64_to_date ( struct isodate * id , const vint64 * ntp ) { ntpcal_split ds ; int32_t ts [ 3 ] ; uint32_t uw , ud , sflag ; ds = ntpcal_daysplit ( ntp ) ; ds . hi += priv_timesplit ( ts , ds . lo ) ; id -> hour = ( uint8_t ) ts [ 0 ] ; id -> minute = ( uint8_t ) ts [ 1 ] ; id -> second = ( uint8_t ) ts [ 2 ] ; ds . hi += DAY_NTP_STARTS - 1 ; sflag = int32_sflag ( ds . hi ) ; ud = int32_to_uint32_2cpl ( ds . hi ) ; uw = sflag ^ ( ( sflag ^ ud ) / DAYSPERWEEK ) ; ud -= uw * DAYSPERWEEK ; ds . hi = uint32_2cpl_to_int32 ( uw ) ; ds . lo = ud ; id -> weekday = ( uint8_t ) ds . lo + 1 ; ds = isocal_split_eraweeks ( ds . hi ) ; id -> year = ( uint16_t ) ds . hi + 1 ; id -> week = ( uint8_t ) ds . lo + 1 ; return ( ds . hi >= 0 && ds . hi < 0x0000FFFF ) ; }
Given a second in the NTP time scale and a pivot, expand the NTP
 time stamp around the pivot and convert into an ISO calendar time
 stamp.
Given a second in the NTP time scale and a pivot expand the NTP time stamp around the pivot and convert into an ISO calendar time stamp .
/*
	 * Split NTP time into days and seconds, shift days into CE
	 * domain and process the parts.
	 */ /* split time part */ /* split days into days and weeks, using floor division in unsigned */ /* shift from NTP to RDN */ /* weekday result    */ /* get year and week in year */ /* elapsed years&week*/ /* shift to current  */