Factorize the localtime_r replacement