Improving logic for days calculation