/* Hinnant's algorithm to calculate the number of days offset from the epoch.  */
static uint32_t hinnant(int y, int m, int d)
/* Hinnant's algorithm to calculate the number of days offset from the epoch.  */
static uint32_t hinnant(int y, int m, int d)
{
	unsigned yoe;
	unsigned doy;
	unsigned doe;
	int era;
	y -= (m <= 2);
	era = ((y >= 0) ? y : (y - 399)) / 400;
	yoe = y - era * 400;
	doy = (153 * (m + ((m > 2) ? -3 : 9)) + 2)/5 + d - 1;
	doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
	return era * 146097 + ((int) doe) - 719468;
}