Refactoring of datetime convertion