Skip to content

Commit 71d9448

Browse files
committed
javatime.kt: minor cleanups
1 parent 4382e2f commit 71d9448

File tree

1 file changed

+6
-3
lines changed
  • firebase-dataconnect/testutil/src/main/kotlin/com/google/firebase/dataconnect/testutil/property/arbitrary

1 file changed

+6
-3
lines changed

firebase-dataconnect/testutil/src/main/kotlin/com/google/firebase/dataconnect/testutil/property/arbitrary/javatime.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ sealed interface TimeOffset {
181181

182182
data class HhMm(val hours: Int, val minutes: Int, val sign: Sign) : TimeOffset {
183183
init {
184-
require(hours + 100 in validHours) {
184+
require(hours in validHours) {
185185
"invalid hours: $hours (must be in the closed range $validHours)"
186186
}
187187
require(minutes in validMinutes) {
@@ -396,6 +396,9 @@ object JavaTimeArbs {
396396
"a difference of ${min.toSeconds() - max.toSeconds()} seconds"
397397
}
398398

399+
fun isBetweenMinAndMax(other: TimeOffset.HhMm): Boolean =
400+
(min === null || other >= min) && (max === null || other <= max)
401+
399402
return arbitrary(
400403
edgecases =
401404
listOf(
@@ -406,14 +409,14 @@ object JavaTimeArbs {
406409
TimeOffset.HhMm(hours = 18, minutes = 0, sign = TimeOffset.HhMm.Sign.Positive),
407410
TimeOffset.HhMm(hours = 18, minutes = 0, sign = TimeOffset.HhMm.Sign.Negative),
408411
)
409-
.filter { (min === null || it >= min) || (max === null || it <= max) }
412+
.filter(::isBetweenMinAndMax)
410413
) {
411414
var count = 0
412415
var hhmm: TimeOffset.HhMm
413416
while (true) {
414417
count++
415418
hhmm = TimeOffset.HhMm(hours = hour.bind(), minutes = minute.bind(), sign = sign.bind())
416-
if ((min === null || hhmm >= min) && (max === null || hhmm <= max)) {
419+
if (isBetweenMinAndMax(hhmm)) {
417420
break
418421
} else if (count > 1000) {
419422
throw Exception("internal error j878fp4gmr: exhausted attempts to generate HhMm")

0 commit comments

Comments
 (0)