stats: Allow sorting and arbitrary time ranges