FreeBSD/contrib/ntp/libntp/ntp_calendar.c
/*
 *---------------------------------------------------------------------
 * Convert a RD into the date part of a 'struct calendar'.
 *---------------------------------------------------------------------
 */
Convert a RD into the date part of a 'struct calendar'.
Convert a RD into the date part of a ' struct calendar ' .
int
ntpcal_rd_to_date(
	struct calendar *jd,
	int32_t		 rd
	)
{
	ntpcal_split split;
	int	     leapy;
	u_int	     ymask;
	jd->weekday = rd % DAYSPERWEEK;
	if (jd->weekday >= DAYSPERWEEK)	
		jd->weekday += DAYSPERWEEK;
	split = ntpcal_split_eradays(rd - 1, &leapy);
	split.hi += 1;
	ymask = 0u - ((split.hi >> 16) == 0);
	jd->year = (uint16_t)(split.hi & ymask);
	jd->yearday = (uint16_t)split.lo + 1;
	split = ntpcal_split_yeardays(split.lo, leapy);
	jd->month    = (uint8_t)split.hi + 1;
	jd->monthday = (uint8_t)split.lo + 1;
	return ymask ? leapy : -1;
}
int ntpcal_rd_to_date ( struct calendar * jd , int32_t rd ) { ntpcal_split split ; int leapy ; u_int ymask ; jd -> weekday = rd % DAYSPERWEEK ; if ( jd -> weekday >= DAYSPERWEEK ) jd -> weekday += DAYSPERWEEK ; split = ntpcal_split_eradays ( rd - 1 , & leapy ) ; split . hi += 1 ; ymask = 0u - ( ( split . hi >> 16 ) == 0 ) ; jd -> year = ( uint16_t ) ( split . hi & ymask ) ; jd -> yearday = ( uint16_t ) split . lo + 1 ; split = ntpcal_split_yeardays ( split . lo , leapy ) ; jd -> month = ( uint8_t ) split . hi + 1 ; jd -> monthday = ( uint8_t ) split . lo + 1 ; return ymask ? leapy : -1 ; }
Convert a RD into the date part of a 'struct calendar'.
Convert a RD into the date part of a ' struct calendar ' .
/* Get day-of-week first. Since rd is signed, the remainder can
	 * be in the range [-6..+6], but the assignment to an unsigned
	 * variable maps the negative values to positive values >=7.
	 * This makes the sign correction look strange, but adding 7
	 * causes the needed wrap-around into the desired value range of
	 * zero to six, both inclusive.
	 */ /* weekday is unsigned! */ /* Get year and day-of-year, with overflow check. If any of the
	 * upper 16 bits is set after shifting to unity-based years, we
	 * will have an overflow when converting to an unsigned 16bit
	 * year. Shifting to the right is OK here, since it does not
	 * matter if the shift is logic or arithmetic.
	 */ /* convert to month and mday */