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

shouldHaveSameMonthAs

infix fun LocalDateTime.shouldHaveSameMonthAs(date: LocalDateTime): 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 has the same month as 10/02/2018 11:30:30, and this assertion should pass for this comparison

Opposite of LocalDateTime.shouldNotHaveSameMonthAs

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

    firstDate should haveSameMonth(secondDate)   //  Assertion passes


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

    firstDate shouldNot haveSameMonth(secondDate)    //  Assertion passes