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

before

fun before(anotherInstant: Instant): Matcher<Instant> fun before(time: LocalTime): Matcher<LocalTime>

Matcher that compares two LocalTimes and checks whether one is before the other

Verifies that two LocalTimes occurs in a certain order, checking that one happened before the other. For example, 12:30:59:2222 is before 12:30:59:3333, and the matcher will have a positive result for this comparison

    val firstTime = LocalTime.of(12:30:59:2222)
    val secondTime = LocalTime.of(12:30:59:3333)

    firstTime shouldBe before(secondTime)     // Assertion passes


    val firstTime = LocalTime.of(12:30:59:2222)
    val secondTime = LocalTime.of(12:30:59:1111)

    firstTime shouldNotBe before(secondTime)  // Assertion passes

See Also

LocalTime.shouldBeBefore

LocalTime.shouldNotBeBefore

fun before(date: LocalDate): Matcher<LocalDate>

Matcher that compares two LocalDates and checks whether one is before the other

Verifies that two LocalDates occurs in a certain order, checking that one happened before the other. For example, 09/02/1998 is before 10/02/1998, and the matcher will have a positive result for this comparison

    val firstDate = LocalDate.of(1998, 2, 9)
    val secondDate = LocalDate.of(1998, 2, 10)

    firstDate shouldBe before(secondDate)     // Assertion passes


    val firstDate = LocalDate.of(1998, 2, 10)
    val secondDate = LocalDate.of(1998, 2, 9)

    firstDate shouldNotBe before(secondDate)  // Assertion passes

See Also

LocalDate.shouldBeBefore

LocalDate.shouldNotBeBefore

fun before(date: LocalDateTime): Matcher<LocalDateTime>

Matcher that compares two LocalDateTimes and checks whether one is before the other

Verifies that two LocalDateTimes occurs in a certain order, checking that one happened before the other. For example, 09/02/1998 00:00:00 is before 09/02/1998 00:00:01, and the matcher will have a positive result for this comparison

    val firstDate = LocalDateTime.of(1998, 2, 9, 0, 0, 0)
    val secondDate = LocalDateTime.of(1998, 2, 9, 0, 0, 1)

    firstDate shouldBe before(secondDate)     // Assertion passes


    val firstDate = LocalDateTime.of(1998, 2, 9, 0, 0, 1)
    val secondDate = LocalDateTime.of(1998, 2, 9, 0, 0, 0)

    firstDate shouldNotBe before(secondDate)  // Assertion passes

See Also

LocalDateTime.shouldBeBefore

LocalDateTime.shouldNotBeBefore

fun before(date: ZonedDateTime): Matcher<ZonedDateTime>

Matcher that compares two ZonedDateTimes and checks whether one is before the other

Verifies that two ZonedDateTimes occurs in a certain order, checking that one happened before the other. 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 the matcher will have a positive result for this comparison

    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 shouldBe before(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 shouldNotBe before(secondDate)  // Assertion passes

See Also

ZonedDateTime.shouldBeBefore

ZonedDateTime.shouldNotBeBefore

fun before(date: OffsetDateTime): Matcher<OffsetDateTime>

Matcher that compares two OffsetDateTimes and checks whether one is before the other

Verifies that two OffsetDateTimes occurs in a certain order, checking that one happened before the other. For example, 09/02/1998 00:00:00 -03:00 is before 09/02/1998 00:00:01 -03:00, and the matcher will have a positive result for this comparison

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

    firstDate shouldBe before(secondDate)     // Assertion passes


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

    firstDate shouldNotBe before(secondDate)  // Assertion passes

See Also

OffsetDateTime.shouldBeBefore

OffsetDateTime.shouldNotBeBefore