clampBetween method
Clamps this DateTime between start and end.
Returns start if this is before the range, end if after, or this
if it already falls within the range.
Throws ArgumentError if start is after end.
Implementation
DateTime clampBetween(DateTime start, DateTime end) {
if (start.isAfter(end)) {
throw ArgumentError(
'Start date ($start) must be before or equal to end date ($end)',
);
}
if (isBefore(start)) return start;
if (isAfter(end)) return end;
return this;
}