The Gemara describes how David Hamelech would spend all night immersed in study and prayer, which leads us to conclude that he must have slept during the day. However in Shulchan Aruch (O”CH 231) the halacha seems to discourage sleep during the daytime. How is this consistent with Dovid Hamelech’s schedule?