Like I mentioned in my previous article, I've been working on refactoring the temporal data handling in Drizzle. The major problem I've been dealing with is poorly or non-documented code. The lack of documentation has led me to rely on the MySQL Manual in some cases, and then additional research and lastly, my own intuition as to what was going on.
One of the earliest cases of me saying "WTF?" was when I was investigating how day numbers were calculated. Here is the original, unmodified code from MySQL (/libmysql/my_time.c:746-778). I've highlighted in blue the massive amount of comments explaining the inner workings of the function and what it is doing.
/* Calculate nr of day since year 0 in new date-system (from 1615) SYNOPSIS calc_daynr() year Year (exact 4 digit year, no year conversions) month Month day Day NOTES: 0000-00-00 is a valid date, and will return …[Read more]