File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -249,8 +249,8 @@ extension DateTimeTimeExtension on DateTime {
249
249
/// ```
250
250
DateTime clamp ({DateTime ? min, DateTime ? max}) {
251
251
assert (
252
- ((min != null ) && (max != null )) ? min.compareTo (max).isNegative : true ,
253
- 'DateTime min has to be before max\n (min: $min - max: $max )' ,
252
+ ((min != null ) && (max != null )) ? ( min.isBefore (max) || (min == max)) : true ,
253
+ 'DateTime min has to be before or equal to max\n (min: $min - max: $max )' ,
254
254
);
255
255
if ((min != null ) && compareTo (min).isNegative) {
256
256
return min;
Original file line number Diff line number Diff line change @@ -640,6 +640,13 @@ void main() {
640
640
throwsA (isA <AssertionError >()),
641
641
);
642
642
});
643
+
644
+ test ('returns min/max if are equal' , () {
645
+ final it = DateTime (2022 , DateTime .september, 1 );
646
+ final min = DateTime (2022 , DateTime .september, 30 );
647
+ final max = min;
648
+ expect (it.clamp (min: min, max: max), min);
649
+ });
643
650
});
644
651
});
645
652
You can’t perform that action at this time.
0 commit comments