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

shouldNotBeWithin

fun ZonedDateTime.shouldNotBeWithin(temporalAmount: TemporalAmount, date: ZonedDateTime): Unit

Asserts that this is NOT within temporalAmount of date

Verifies that this is not within temporalAmount of date. For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo is not within 3 days of 25/02/1998 10:00:00 -03:00 America/Sao_Paulo, and this assertion should pass for this comparison.

Opposite of ZonedDateTime.shouldBeWithin

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

    firstDate.shouldNotBeWithin(Period.ofDays(3), secondDate) // Assertion passes


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

    firstDate.shouldNotBeWithin(Period.ofDays(3), secondDate)   // Assertion fails, firstDate is within 3 days of secondDate, and we expected not to