Fix Timeperiod calculation