time-selector: format time label when the day period changes

Also, factor out date formatting code.