Make data.py work when periods span midnight