date-selector: factor out duplicated code