improved localtime logic