My eyes are veritably crossing and dilating trying to look at your get_timestamp function... Wouldn't everything be incredibly simpler if you did it all with seconds, storing times as seconds since the epoch, durations as periods of seconds, and just performing a simple mathematical subtraction to figure out whether something had expired? Maybe I'm missing something, but I think you're passing up an opportunity to do something simple simply, giving rise, as you've noticed, to more opportunities for code defects.