kotest-assertions / io.kotest.matchers.date / shouldBeBefore

shouldBeBefore

infix fun <ERROR CLASS>.shouldBeBefore(other: <ERROR CLASS>): <ERROR CLASS>

Asserts that this is before other

Verifies that this is before other, comparing every field in the OffsetDateTime. For example, 09/02/1998 00:00:00 -03:00 is before 09/02/1998 00:00:01 -03:00, and this assertion should pass for this comparison.

Opposite of Date.shouldNotBeBefore

    val firstDate = Date(1998, 2, 9, 0, 0, 0, 0, ZoneOffset.ofHours(-3))
    val secondDate = Date(1998, 2, 9, 0, 0, 1, 0, ZoneOffset.ofHours(-3))

    firstDate shouldBeBefore secondDate    // Assertion passes


    val firstDate = Date(1998, 2, 9, 0, 0, 1, 0, ZoneOffset.ofHours(-3))
    val secondDate = Date(1998, 2, 9, 0, 0, 0, 0, ZoneOffset.ofHours(-3))

    firstDate shouldBeBefore secondDate     // Assertion fails, firstDate is one second after secondDate

See Also

Date.shouldNotBeAfter