Fixed issue with date calculations