Simplify common code into a single function

Take three different time/date routines into common function

Signed-off-by: Mark Harvey <markh794@gmail.com>