In a 2017 study, researchers looked at more than 2400 species of mammals today and created algorithms to study the genetic transitions from nocturnality to diurnality.
And in a 2014 paper, when the researchers looked even farther back in the fossil record, they found that nocturnality evolved in vertebrates before the earliest mammals appeared, within a lineage known as synapsids.