kotest-assertions-core / io.kotest.matchers.date / java.time.OffsetDateTime / shouldNotHaveSameYearAs

shouldNotHaveSameYearAs

infix fun OffsetDateTime.shouldNotHaveSameYearAs(date: OffsetDateTime): Unit

Asserts that this year is NOT the same as date's year

Verifies that this year isn't the same as date's year, ignoring any other fields. For example, 09/02/1998 10:00:00 -03:00 doesn't have the same year as 09/02/2018 10:00:00 -03:00, and this assertion should pass for this comparison

Opposite of OffsetDateTime.shouldHaveSameYearAs

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

    firstDate shouldNotHaveSameYearAs secondDate    // Assertion passes


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

    firstDate shouldNotHaveSameYearAs secondDate    // Assertion fails, 1998 == 1998 and we expected a difference