added midnight handling (untested)