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

shouldNotHaveSameYearAs

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

Opposite of ZonedDateTime.shouldHaveSameYearAs

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

    firstDate shouldNotHaveSameYearAs secondDate    //  Assertion passes


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

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