slotAt method

int slotAt(
  1. Instant at
)

The slot holding an instant (its index), or -1 outside.

Implementation

int slotAt(Instant at) {
  final ms = at.epochMilliseconds;
  if (ms < start.epochMilliseconds || ms >= end.epochMilliseconds || _starts.isEmpty) return -1;
  // The last slot starting at or before it.
  var lo = 0;
  var hi = _starts.length - 1;
  while (lo < hi) {
    final mid = (lo + hi + 1) >> 1;
    if (_starts[mid] <= ms) {
      lo = mid;
    } else {
      hi = mid - 1;
    }
  }
  return lo;
}