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

shouldHaveSameMonthAs

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

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

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

Opposite of ZonedDateTime.shouldNotHaveSameMonthAs

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

    firstDate should haveSameMonth(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, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))

    firstDate shouldNot haveSameMonth(secondDate)    //  Assertion passes