kotest-assertions-core / io.kotest.matchers.date / haveSameHours

haveSameHours

fun haveSameHours(time: LocalTime): Matcher<LocalTime>

Matcher that compares hours of LocalTimes

Verifies that two times have exactly the same hours, ignoring any other fields. For example, 23:59:30:9999 has the same hours as 23:01:02:3333, and the matcher will have a positive result for this comparison

    val firstTime = LocalTime.of(23, 59, 30, 1000)
    val secondTime = LocalTime.of(23, 1, 2, 3333)

    firstTime should haveSameHours(secondTime)   //  Assertion passes


    val firstTime = LocalTime.of(23, 59, 30, 1000)
    val secondTime = LocalTime.of(16, 59, 30, 1000)

    firstTime shouldNot haveSameHours(secondTime)   //  Assertion passes

See Also

LocalTime.shouldHaveSameHoursAs

LocalTime.shouldNotHaveSameHoursAs