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

shouldNotHaveSameYearAs

infix fun LocalDateTime.shouldNotHaveSameYearAs(date: LocalDateTime): 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 doesn't have the same year as 09/02/2018 10:00:00, and this assertion should pass for this comparison

Opposite of LocalDateTime.shouldHaveSameYearAs

    val firstDate = LocalDateTime.of(2018, 2, 9, 10, 0, 0)
    val secondDate = LocalDateTime.of(1998, 3, 10, 11, 30, 30)

    firstDate shouldNotHaveSameYearAs secondDate    //  Assertion passes


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

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