// Compute the day number since the start of year 1. This clever
// expression is thanks to Tony Finch; see his blog post for a
// detailed explanation of what's going on here:
// https://dotat.at/@/2008-09-10-counting-the-days.html
return year * 1461 / 4 - year / 100 + year / 400 + mon * 153 / 5 + day - 428;
}
Assuming we want to model the proleptic Gregorian calendar, it would be nice if the output was linear over all inputs. At the moment, for example, daynum(0, 2, 29) and daynum(0, 3, 1) both return -305.