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

shouldHaveSameDayAs

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

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

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

Opposite of ZonedDateTime.shouldNotHaveSameDayAs

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

    firstDate shouldHaveSameDayAs secondDate   // Assertion passes


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

    firstDate shouldHaveSameDayAs secondDate   // Assertion fails, 9 != 10