Skip to content

Commit 84350da

Browse files
committed
Fix duration min/max bug
1 parent f518e3f commit 84350da

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/src/extensions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ extension DurationTimeExtension on Duration {
301301
/// ```
302302
Duration clamp({Duration? min, Duration? max}) {
303303
assert(
304-
((min != null) && (max != null)) ? min.compareTo(max).isNegative : true,
304+
((min != null) && (max != null)) ? min.compareTo(max) <= 0 : true,
305305
'Duration min has to be shorter than max\n(min: $min - max: $max)',
306306
);
307307
if ((min != null) && compareTo(min).isNegative) {

test/time_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,13 @@ void main() {
744744
throwsA(isA<AssertionError>()),
745745
);
746746
});
747+
748+
test('returns min/max if are equal', () {
749+
final it = Duration(days: -0);
750+
final min = Duration(days: 5);
751+
final max = min;
752+
expect(it.clamp(min: min, max: max), min);
753+
});
747754
});
748755
});
749756
}

0 commit comments

Comments
 (0)