Updated algorithm that detects dawn