Fix date calculation logic