Fix bug #5407: Count steps correctly if the counter is running overnight