clamp method

CalendarSelection clamp({
  1. Date? min,
  2. Date? max,
})

Returns a copy of this CalendarSelection clamped to min, max.

If min is null, the start date won't be clamped. Likewise for max. Start and end dates can be null to represent unbounded ranges.

Implementation

CalendarSelection clamp({Date? min, Date? max}) {
  // If min/max is null, default to start/end.
  min = min ?? start;
  max = max ?? end;

  // If they're still null, use as-is; otherwise clamp the range.
  if (min != null) {
    min = laterOf(min, start ?? min);
  }
  if (max != null) {
    max = earlierOf(max, end ?? max);
  }

  return CalendarSelection(id, min, max);
}