Fix sorting issue with date ranges