kotest-assertions-core / io.kotest.matchers.date / haveSameDay

haveSameDay

fun haveSameDay(date: LocalDate): Matcher<LocalDate>

Matcher that compares days of LocalDates

Verifies that two dates have exactly the same day, ignoring any other fields. For example, 09/02/1998 has the same day as 09/03/2018, and the matcher will have a positive result for this comparison

    val firstDate = LocalDate.of(1998, 2, 9)
    val secondDate = LocalDate.of(2018, 3, 9)

    firstDate should haveSameDay(secondDate)   //  Assertion passes


    val firstDate = LocalDate.of(1998, 2, 9)
    val secondDate = LocalDate.of(1998, 2, 10)

    firstDate shouldNot haveSameDay(secondDate)    //  Assertion passes

See Also

LocalDate.shouldHaveSameDayAs

LocalDate.shouldNotHaveSameDayAs

fun haveSameDay(date: LocalDateTime): Matcher<LocalDateTime>

Matcher that compares days of LocalDateTimes

Verifies that two DateTimes have exactly the same day, ignoring any other fields. For example, 09/02/1998 10:00:00 has the same day as 09/03/2018 11:30:30, and the matcher will have a positive result for this comparison

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

    firstDate should haveSameDay(secondDate)   // Assertion passes


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

    firstDate shouldNot haveSameDay(secondDate)    // Assertion passes

See Also

LocalDateTime.shouldHaveSameDayAs

LocalDateTime.shouldNotHaveSameDayAs

fun haveSameDay(date: ZonedDateTime): Matcher<ZonedDateTime>

Matcher that compares days of ZonedDateTimes

Verifies that two ZonedDateTimes have exactly the same 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 the matcher will have a positive result for this comparison

    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 should haveSameDay(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 shouldNot haveSameDay(secondDate)    // Assertion passes

See Also

ZonedDateTime.shouldHaveSameDayAs

ZonedDateTime.shouldNotHaveSameDayAs

fun haveSameDay(date: OffsetDateTime): Matcher<OffsetDateTime>

Matcher that compares days of OffsetDateTimes

Verifies that two ZonedDateTimes have exactly the same day, ignoring any other fields. For example, 09/02/1998 10:00:00 -03:00 has the same day as 09/03/2018 11:30:30 -05:00, and the matcher will have a positive result for this comparison

    val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))
    val secondDate = OffsetDateTime.of(2018, 3, 9, 11, 30, 30, 30, ZoneOffset.ofHours(-5))

    firstDate should haveSameDay(secondDate)   // Assertion passes


    val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))
    val secondDate = OffsetDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneOffset.ofHours(-3))

    firstDate shouldNot haveSameDay(secondDate)    // Assertion passes

See Also

OffsetDateTime.shouldHaveSameDayAs

OffsetDateTime.shouldNotHaveSameDayAs