sortedByTimeOnly method
Returns a new list sorted based on the time extracted from the given key function.
The key function should return a DateTime value from which the time is extracted
(ignoring the date).
Implementation
List<T> sortedByTimeOnly(DateTime key(T e), {bool reversed = false}) {
List<T> sortedList = List<T>.from(this);
sortedList.sort((a, b) {
final Duration timeA =
Duration(hours: key(a).hour, minutes: key(a).minute, seconds: key(a).second);
final Duration timeB =
Duration(hours: key(b).hour, minutes: key(b).minute, seconds: key(b).second);
return timeA.compareTo(timeB);
});
return reversed ? sortedList.reversed.toList() : sortedList;
}