Skip to content

Commit f518e3f

Browse files
author
FELIPE EDUARDO MORSCHEL
committed
Fix wrong assertion when equal
1 parent a5d7b7b commit f518e3f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/src/extensions.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ extension DateTimeTimeExtension on DateTime {
249249
/// ```
250250
DateTime clamp({DateTime? min, DateTime? max}) {
251251
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)',
254254
);
255255
if ((min != null) && compareTo(min).isNegative) {
256256
return min;

test/time_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,13 @@ void main() {
640640
throwsA(isA<AssertionError>()),
641641
);
642642
});
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+
});
643650
});
644651
});
645652

0 commit comments

Comments
 (0)