fun within(period: Period, date: LocalDate): Matcher<LocalDate>
Matcher that compares two LocalDates and checks whether one is within period of the other
Verifies that two LocalDates are within a certain period. For example, 09/02/1998 is within 3 days of 10/02/1998, and the matcher will have a positive result for this comparison.
val firstDate = LocalDate.of(1998, 2, 9)
val secondDate = LocalDate.of(1998, 2, 10)
firstDate shouldBe within(Period.ofDays(3), secondDate) // Assertion passes
val firstDate = LocalDate.of(1998, 2, 9)
val secondDate = LocalDate.of(1998, 2, 25)
firstDate shouldNotBe within(Period.ofDays(3), secondDate) // Assertion passes
See Also
fun within(temporalAmount: TemporalAmount, date: LocalDateTime): Matcher<LocalDateTime>
Matcher that compares two LocalDateTimes and checks whether one is within temporalAmount of the other
Verifies that two LocalDateTimes are within a certain period. For example, 09/02/1998 10:00:00 is within 3 days of 10/02/1998 10:00:00, 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(1998, 2, 10, 10, 0, 0)
firstDate shouldBe within(Period.ofDays(3), secondDate) // Assertion passes
val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)
val secondDate = LocalDateTime.of(1998, 2, 25, 10, 0, 0)
firstDate shouldNotBe within(Period.ofDays(3), secondDate) // Assertion passes
See Also
LocalDateTime.shouldNotBeWithin
fun within(temporalAmount: TemporalAmount, date: ZonedDateTime): Matcher<ZonedDateTime>
Matcher that compares two ZonedDateTimes and checks whether one is within temporalAmount of the other
Verifies that two ZonedDateTimes are within a certain period. For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo is within 3 days of 10/02/1998 10:00:00 -03:00 America/Sao_Paulo, 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(1998, 2, 10, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))
firstDate shouldBe within(Period.ofDays(3), 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, 25, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))
firstDate shouldNotBe within(Period.ofDays(3), secondDate) // Assertion passes
See Also
ZonedDateTime.shouldNotBeWithin
fun within(temporalAmount: TemporalAmount, date: OffsetDateTime): Matcher<OffsetDateTime>
Matcher that compares two OffsetDateTimes and checks whether one is within temporalAmount of the other
Verifies that two OffsetDateTimes are within a certain period. For example, 09/02/1998 10:00:00 -03:00 is within 3 days of 10/02/1998 10:00:00 -03: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(1998, 2, 10, 10, 0, 0, 0, ZoneOffset.ofHours(-3))
firstDate shouldBe within(Period.ofDays(3), secondDate) // Assertion passes
val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))
val secondDate = OffsetDateTime.of(1998, 2, 25, 10, 0, 0, 0, ZoneOffset.ofHours(-3))
firstDate shouldNotBe within(Period.ofDays(3), secondDate) // Assertion passes
See Also