Ported date.c (for approxidate_careful) from git.git revision aa39b85. Trimmed out the parts we're not using.