kotest-assertions-core / io.kotest.matchers.date / java.time.ZonedDateTime / shouldBeBefore

shouldBeBefore

infix fun ZonedDateTime.shouldBeBefore(date: ZonedDateTime): Unit

Asserts that this is before date

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

Opposite of ZonedDateTime.shouldNotBeBefore

    val firstDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))
    val secondDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneId.of("America/Sao_Paulo"))

    firstDate shouldBeBefore secondDate    // Assertion passes


    val firstDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneId.of("America/Sao_Paulo"))
    val secondDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))

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

See Also

ZonedDateTime.shouldNotBeAfter