FreeBSD/contrib/ntp/libntp/ntp_calendar.c
/*
 *---------------------------------------------------------------------
 * Given a number of elapsed days in a year and a leap year indicator,
 * split the number of elapsed days into the number of elapsed months in
 * 'res.hi' and the number of elapsed days of that month in 'res.lo'.
 *
 * This function will fail and return {-1,-1} if the number of elapsed
 * days is not in the valid range!
 *---------------------------------------------------------------------
 */
Given a number of elapsed days in a year and a leap year indicator,
split the number of elapsed days into the number of elapsed months in
'res.hi' and the number of elapsed days of that month in 'res.lo'.

This function will fail and return {-1,-1} if the number of elapsed
days is not in the valid range!
Given a number of elapsed days in a year and a leap year indicator split the number of elapsed days into the number of elapsed months in ' res . hi ' and the number of elapsed days of that month in ' res . lo ' . This function will fail and return { - 1 - 1 } if the number of elapsed days is not in the valid range!
ntpcal_split
ntpcal_split_yeardays(
	int32_t eyd,
	int     isleapyear
	)
{
	ntpcal_split    res;
	const uint16_t *lt;	
	lt = real_month_table[(isleapyear != 0)];
	if (0 <= eyd && eyd < lt[12]) {
		res.hi = eyd >> 5;	   
		if (lt[res.hi + 1] <= eyd) 
			res.hi += 1;
		res.lo = eyd - lt[res.hi];
	} else {
		res.lo = res.hi = -1;
	}
	return res;
}
ntpcal_split ntpcal_split_yeardays ( int32_t eyd , int isleapyear ) { ntpcal_split res ; const uint16_t * lt ; lt = real_month_table [ ( isleapyear != 0 ) ] ; if ( 0 <= eyd && eyd < lt [ 12 ] ) { res . hi = eyd >> 5 ; if ( lt [ res . hi + 1 ] <= eyd ) res . hi += 1 ; res . lo = eyd - lt [ res . hi ] ; } else { res . lo = res . hi = -1 ; } return res ; }
Given a number of elapsed days in a year and a leap year indicator,
 split the number of elapsed days into the number of elapsed months in
 'res.hi' and the number of elapsed days of that month in 'res.lo'.
Given a number of elapsed days in a year and a leap year indicator split the number of elapsed days into the number of elapsed months in ' res . hi ' and the number of elapsed days of that month in ' res . lo ' .
/* month length table	*/ /* check leap year flag and select proper table */ /* get zero-based month by approximation & correction step */ /* approx month; might be 1 too low */ /* fixup approximative month value  */