Fixing date calculation logic