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

haveSameNanos

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

Matcher that compares nanos of LocalTimes

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

    val firstTime = LocalTime.of(23, 59, 30, 1000)
    val secondTime = LocalTime.of(12, 27, 05, 1000)

    firstTime should haveSameNanos(secondTime)   //  Assertion passes


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

    firstTime shouldNot haveSameNanos(secondTime)   //  Assertion passes

See Also

LocalTime.shouldHaveSameNanosAs

LocalTime.shouldNotHaveSameNanosAs