periodicMean function
ZonedDateTime
periodicMean()
Calculates the mean for a series on date objects
Implementation
ZonedDateTime periodicMean(List<ZonedDateTime> dateTimes,
List<ZonedDateTime> references, LocalDateTime reference) {
// remove nan
final ZonedDateTime placeholder = ZonedDateTime.now().nan;
// rewrite using expand instead of zip
final List<int> rawShifts = zip(<List<ZonedDateTime>>[dateTimes, references])
.where((List<ZonedDateTime> element) => element[0] != placeholder)
.map((List<ZonedDateTime> pair) => pair[0].difference(pair[1]).inSeconds)
.toList();
if (rawShifts.isEmpty) {
return ZonedDateTime.now().nan;
}
;
return ZonedDateTimeNaN.fromLocalDateTime(
reference.add(Duration(seconds: rawShifts.average.toInt())));
}