Added unit tests and fixed date calculations