Fix bug in date calculation