FreeBSD/contrib/ntp/libntp/ntp_calendar.c
/*
 *---------------------------------------------------------------------
 * Convert a number of elapsed month in a year into elapsed days in year.
 *
 * The month will be normalized, and 'res.hi' will contain the
 * excessive years that must be considered when converting the years,
 * while 'res.lo' will contain the number of elapsed days since start
 * of the year.
 *
 * This code uses the shifted-month-approach to convert month to days,
 * because then there is no need to have explicit leap year
 * information.	 The slight disadvantage is that for most month values
 * the result is a negative value, and the year excess is one; the
 * conversion is then simply based on the start of the following year.
 *---------------------------------------------------------------------
 */
Convert a number of elapsed month in a year into elapsed days in year.
The month will be normalized, and 'res.hi' will contain the
excessive years that must be considered when converting the years,
while 'res.lo' will contain the number of elapsed days since start
of the year.

This code uses the shifted-month-approach to convert month to days,
because then there is no need to have explicit leap year
information.  The slight disadvantage is that for most month values
the result is a negative value, and the year excess is one; the
conversion is then simply based on the start of the following year.
Convert a number of elapsed month in a year into elapsed days in year . The month will be normalized and ' res . hi ' will contain the excessive years that must be considered when converting the years while ' res . lo ' will contain the number of elapsed days since start of the year . This code uses the shifted - month - approach to convert month to days because then there is no need to have explicit leap year information . The slight disadvantage is that for most month values the result is a negative value and the year excess is one ; the conversion is then simply based on the start of the following year .
ntpcal_split
ntpcal_days_in_months(
	int32_t m
	)
{
	ntpcal_split res;
	res.lo  = m + 10;
	res.hi  = (res.lo >= 12);
	if (res.hi)
		res.lo -= 12;
	if (res.lo < 0 || res.lo >= 12) {
		uint32_t mu, Q, sflag;
		sflag = int32_sflag(res.lo);
		mu    = int32_to_uint32_2cpl(res.lo);
		Q     = sflag ^ ((sflag ^ mu) / 12u);
		res.hi += uint32_2cpl_to_int32(Q);
		res.lo  = mu - Q * 12u;
	}
	res.lo = shift_month_table[res.lo] - 306;
	return res;
}
ntpcal_split ntpcal_days_in_months ( int32_t m ) { ntpcal_split res ; res . lo = m + 10 ; res . hi = ( res . lo >= 12 ) ; if ( res . hi ) res . lo -= 12 ; if ( res . lo < 0 || res . lo >= 12 ) { uint32_t mu , Q , sflag ; sflag = int32_sflag ( res . lo ) ; mu = int32_to_uint32_2cpl ( res . lo ) ; Q = sflag ^ ( ( sflag ^ mu ) / 12u ) ; res . hi += uint32_2cpl_to_int32 ( Q ) ; res . lo = mu - Q * 12u ; } res . lo = shift_month_table [ res . lo ] - 306 ; return res ; }
Convert a number of elapsed month in a year into elapsed days in year.
Convert a number of elapsed month in a year into elapsed days in year .
/* Add ten months and correct if needed. (It likely is...) */ /* if still out of range, normalise by floor division ... */ /* get cummulated days in year with unshift */