fun haveSameYear(date: LocalDate): Matcher<LocalDate>
Matcher that compares years of LocalDates
Verifies that two dates have exactly the same year, ignoring any other fields. For example, 09/02/1998 has the same year as 10/03/1998, and the matcher will have a positive result for this comparison
val firstDate = LocalDate.of(1998, 2, 9)
val secondDate = LocalDate.of(1998, 3, 10)
firstDate should haveSameYear(secondDate) // Assertion passes
val firstDate = LocalDate.of(1998, 2, 9)
val secondDate = LocalDate.of(2018, 2, 9)
firstDate shouldNot haveSameYear(secondDate) // Assertion passes
See Also
LocalDate.shouldHaveSameYearAs
LocalDate.shouldNotHaveSameYearAs
fun haveSameYear(date: LocalDateTime): Matcher<LocalDateTime>
Matcher that compares years of LocalDateTimes
Verifies that two DateTimes have exactly the same year, ignoring any other fields. For example, 09/02/1998 10:00:00 has the same year as 10/03/1998 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(1998, 3, 10, 11, 30, 30)
firstDate should haveSameYear(secondDate) // Assertion passes
val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)
val secondDate = LocalDateTime.of(2018, 2, 9, 10, 0, 0)
firstDate shouldNot haveSameYear(secondDate) // Assertion passes
See Also
LocalDateTime.shouldHaveSameYearAs
LocalDateTime.shouldNotHaveSameYearAs
fun haveSameYear(date: ZonedDateTime): Matcher<ZonedDateTime>
Matcher that compares years of ZonedDateTimes
Verifies that two ZonedDateTimes have exactly the same year, ignoring any other fields. For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo has the same year as 10/03/1998 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(1998, 3, 10, 11, 30, 30, 30, ZoneId.of("America/Chicago"))
firstDate should haveSameYear(secondDate) // Assertion passes
val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))
val secondDate = ZonedDateTime.of(2018, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))
firstDate shouldNot haveSameYear(secondDate) // Assertion passes
See Also
ZonedDateTime.shouldHaveSameYearAs
ZonedDateTime.shouldNotHaveSameYearAs
fun haveSameYear(date: OffsetDateTime): Matcher<OffsetDateTime>
Matcher that compares years of OffsetDateTimes
Verifies that two ZonedDateTimes have exactly the same year, ignoring any other fields. For example, 09/02/1998 10:00:00 -03:00 has the same year as 10/03/1998 11:30:30 -05:00, and the matcher will have a positive result for this comparison
val firstDate = OffsetDateTime.of(2018, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))
val secondDate = OffsetDateTime.of(1998, 2, 9, 19, 0, 0, 0, ZoneOffset.ofHours(-3))
firstDate shouldNotHaveSameYearAs secondDate // Assertion passes
val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))
val secondDate = OffsetDateTime.of(1998, 3, 10, 1, 30, 30, 30, ZoneOffset.ofHours(-5))
firstDate shouldNotHaveSameYearAs secondDate // Assertion fails, 1998 == 1998, and we expected a difference
See Also