Kotest Kotlinx Datetime Matchers

Explains Kotlinx Datetime matchers.

Matchers for the Kotlinx Datetime library are provided by the kotest-assertions-kotlinx-time module.

LocalDate Description
date.shouldHaveSameYearAs(otherDate) Checks that the date has the same year as the given date.
date.shouldHaveSameMonthAs(otherDate) Checks that the date has the same month as the given date.
date.shouldHaveSameDayAs(otherDate) Checks that the date has the same day of month as the given date.
date.shouldBeBefore(otherDate) Checks that the date is before the given date.
date.shouldBeAfter(otherDate) Checks that the date is after the given date.
date.shouldBeWithin(period, otherDate) Checks that the date is within the period of the given date.
date.shouldBeWithin(duration, otherDate) Checks that the date is within the duration of the given date.
date.shouldBeBetween(firstDate, secondDate) Checks that the date is between firstDate and secondDate.
date.shouldHaveYear(year) Checks that the date has the correct year.
date.shouldHaveMonth(month) Checks that the date has the correct month.
date.shouldHaveDayOfYear(day) Checks that the date has the exact day of year.
date.shouldHaveDayOfMonth(day) Checks that the date has the correct day of month.
date.shouldHaveDayOfWeek(day) Checks that the date has the correct day of week.
date.shouldHaveHour(hour) Checks that the date has the correct hour.
date.shouldHaveMinute(Minute) Checks that the date has the correct minute.
date.shouldHaveSecond(second) Checks that the date has the correct second.
date.shouldHaveNano(nano) Checks that the date has the correct nanosecond.
LocalDateTime Description
time.shouldHaveSameHoursAs(otherTime) Checks that the time has the same hour as the given time.
time.shouldHaveSameMinutesAs(otherTime) Checks that the time has the same minute as the given time.
time.shouldHaveSameSecondsAs(otherTime) Checks that the time has the same second as the given time.
time.shouldHaveSameNanosAs(otherTime) Checks that the time has the same nanosecond as the given time.
time.shouldBeBefore(otherTime) Checks that the time is before the given time.
time.shouldBeAfter(otherTime) Checks that the time is after the given time.
time.shouldBeBetween(firstTime, secondTime) Checks that the time is between firstTime and secondTime.
Instant Description
instant.shouldBeAfter(anotherInstant) Checks that the instant occurs after anotherInstant.
instant.shouldBeBefore(anotherInstant) Checks that the instant is before anotherInstant.
instant.shouldBeBetween(fromInstant, toInstant) Checks that the instant is between fromInstant and toInstant.

References