closestTo static method

LiveBroadcastItem closestTo(
  1. List<LiveBroadcastItem> items, {
  2. DateTime? dateTime,
})

Implementation

static LiveBroadcastItem closestTo(List<LiveBroadcastItem> items,
    {DateTime? dateTime}) {
  final check = dateTime ?? DateTime.now().toUtc();

  return items.reduce((a, b) {
    print(
        'a: ${a.defaultStartTime().difference(check).abs().inSeconds}, b: ${b.defaultStartTime().difference(check).abs().inSeconds}');

    return a.defaultStartTime().difference(check).abs() <
            b.defaultStartTime().difference(check).abs()
        ? a
        : b;
  });
}