unit test datetime code. refactoring and bug fixing