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

shouldHaveSameYearAs

infix fun ZonedDateTime.shouldHaveSameYearAs(date: ZonedDateTime): Unit

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

Verifies that this year is the same as date's year, ignoring any other fields. For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo has the same year as 10/03/1998 11:30:30 -05:00 America/Chicago, and this assertion should pass for this comparison

Opposite of ZonedDateTime.shouldNotHaveSameYearAs

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

    firstDate shouldHaveSameYearAs secondDate   //  Assertion passes


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

    firstDate shouldHaveSameYearAs secondDate   //  Assertion fails, 2018 != 1998