This is some code I had previously written, adapted to (mostly) libcfu coding style. The API is very similar to that of the existing (to be eventually removed) cfutime.