Skip to content

Commit 34f3837

Browse files
committed
Add range precondition to Date generators
1 parent 2216b0c commit 34f3837

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Sources/PropertyBased/Gen+Date.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ extension Gen where Value == Date {
117117
/// - Parameter range: A range which contains all generated dates. Undefined bounds will be set to 60 years from the other bound.
118118
/// - Returns: A new generator.
119119
public static func dateTime(in range: Range<Date>) -> Generator<Date, DateTimeShrink> {
120+
precondition(!range.isEmpty, "Range must not be empty")
121+
120122
let interval = range.lowerBound.timeIntervalSinceReferenceDate..<range.upperBound.timeIntervalSinceReferenceDate
121123
let end = Date().timeIntervalSinceReferenceDate
122124

@@ -215,6 +217,8 @@ extension Gen where Value == Date {
215217
/// - Parameter range: A range which contains all generated dates. Undefined bounds will be set to 60 years from the other bound.
216218
/// - Returns: A new generator.
217219
public static func date(in range: Range<Date>) -> Generator<Date, Shrink.Integer<Int>> {
220+
precondition(!range.isEmpty, "Range must not be empty")
221+
218222
let newUpper = range.upperBound.timeIntervalSinceReferenceDate - secondsPerDay
219223
return date(in: range.lowerBound...Date(timeIntervalSinceReferenceDate: newUpper))
220224
}

0 commit comments

Comments
 (0)