How to use LocalDateTime.shouldBeWithin method of io.kotest.matchers.date.matchers class

Best Kotest code snippet using io.kotest.matchers.date.matchers.LocalDateTime.shouldBeWithin

matchers.kt

Source:matchers.kt Github

copy

Full Screen

1package io.kotest.matchers.date2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNot7import io.kotest.matchers.shouldNotBe8import java.time.DayOfWeek9import java.time.LocalDate10import java.time.LocalDateTime11import java.time.Month12import java.time.OffsetDateTime13import java.time.Period14import java.time.ZonedDateTime15import java.time.temporal.TemporalAmount16/**17 * Asserts that this year is the same as [date]'s year18 *19 * Verifies that this year is the same as [date]'s year, ignoring any other fields.20 * For example, 09/02/1998 has the same year as 10/03/1998, and this assertion should pass for this comparison21 *22 * Opposite of [LocalDate.shouldNotHaveSameYearAs]23 *24 * ```25 * val firstDate = LocalDate.of(1998, 2, 9)26 * val secondDate = LocalDate.of(1998, 3, 10)27 *28 * firstDate shouldHaveSameYearAs secondDate // Assertion passes29 *30 *31 * val firstDate = LocalDate.of(2018, 2, 9)32 * val secondDate = LocalDate.of(1998, 2, 9)33 *34 * firstDate shouldHaveSameYearAs secondDate // Assertion fails, 2018 != 199835 ```36 */37infix fun LocalDate.shouldHaveSameYearAs(date: LocalDate) = this should haveSameYear(date)38/**39 * Asserts that this year is NOT the same as [date]'s year40 *41 * Verifies that this year isn't the same as [date]'s year, ignoring any other fields.42 * For example, 09/02/1998 doesn't have the same year as 09/02/2018, and this assertion should pass for this comparison43 *44 * Opposite of [LocalDate.shouldHaveSameYearAs]45 *46 * ```47 * val firstDate = LocalDate.of(2018, 2, 9)48 * val secondDate = LocalDate.of(1998, 2, 9)49 *50 * firstDate shouldNotHaveSameYearAs secondDate // Assertion passes51 *52 *53 * val firstDate = LocalDate.of(1998, 2, 9)54 * val secondDate = LocalDate.of(1998, 3, 10)55 *56 * firstDate shouldNotHaveSameYearAs secondDate // Assertion fails, 1998 == 1998, and we expected a difference57 * ```58 */59infix fun LocalDate.shouldNotHaveSameYearAs(date: LocalDate) = this shouldNot haveSameYear(date)60/**61 * Matcher that compares years of LocalDates62 *63 * Verifies that two dates have exactly the same year, ignoring any other fields.64 * For example, 09/02/1998 has the same year as 10/03/1998, and the matcher will have a positive result for this comparison65 *66 * ```67 * val firstDate = LocalDate.of(1998, 2, 9)68 * val secondDate = LocalDate.of(1998, 3, 10)69 *70 * firstDate should haveSameYear(secondDate) // Assertion passes71 *72 *73 * val firstDate = LocalDate.of(1998, 2, 9)74 * val secondDate = LocalDate.of(2018, 2, 9)75 *76 * firstDate shouldNot haveSameYear(secondDate) // Assertion passes77 * ```78 *79 * @see [LocalDate.shouldHaveSameYearAs]80 * @see [LocalDate.shouldNotHaveSameYearAs]81 */82fun haveSameYear(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {83 override fun test(value: LocalDate): MatcherResult =84 MatcherResult(85 value.year == date.year,86 { "$value should have year ${date.year}" },87 {88 "$value should not have year ${date.year}"89 })90}91/**92 * Asserts that this year is the same as [date]'s year93 *94 * Verifies that this year is the same as [date]'s year, ignoring any other fields.95 * For example, 09/02/1998 10:00:00 has the same year as 10/03/1998 11:30:30, and this assertion should pass for this comparison96 *97 * Opposite of [LocalDateTime.shouldNotHaveSameYearAs]98 *99 * ```100 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)101 * val secondDate = LocalDateTime.of(1998, 3, 10, 11, 30, 30)102 *103 * firstDate shouldHaveSameYearAs secondDate // Assertion passes104 *105 *106 * val firstDate = LocalDateTime.of(2018, 2, 9, 10, 0, 0)107 * val secondDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)108 *109 * firstDate shouldHaveSameYearAs secondDate // Assertion fails, 2018 != 1998110 * ```111 */112infix fun LocalDateTime.shouldHaveSameYearAs(date: LocalDateTime) = this should haveSameYear(date)113/**114 * Asserts that this year is NOT the same as [date]'s year115 *116 * Verifies that this year isn't the same as [date]'s year, ignoring any other fields.117 * For example, 09/02/1998 10:00:00 doesn't have the same year as 09/02/2018 10:00:00, and this assertion should pass for this comparison118 *119 * Opposite of [LocalDateTime.shouldHaveSameYearAs]120 *121 * ```122 * val firstDate = LocalDateTime.of(2018, 2, 9, 10, 0, 0)123 * val secondDate = LocalDateTime.of(1998, 3, 10, 11, 30, 30)124 *125 * firstDate shouldNotHaveSameYearAs secondDate // Assertion passes126 *127 *128 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)129 * val secondDate = LocalDateTime.of(1998, 3, 10, 1, 30, 30)130 *131 * firstDate shouldNotHaveSameYearAs secondDate // Assertion fails, 1998 == 1998, and we expected a difference132 * ```133 */134infix fun LocalDateTime.shouldNotHaveSameYearAs(date: LocalDateTime) = this shouldNot haveSameYear(date)135/**136 * Matcher that compares years of LocalDateTimes137 *138 * Verifies that two DateTimes have exactly the same year, ignoring any other fields.139 * 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 comparison140 *141 * ```142 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)143 * val secondDate = LocalDateTime.of(1998, 3, 10, 11, 30, 30)144 *145 * firstDate should haveSameYear(secondDate) // Assertion passes146 *147 *148 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)149 * val secondDate = LocalDateTime.of(2018, 2, 9, 10, 0, 0)150 *151 * firstDate shouldNot haveSameYear(secondDate) // Assertion passes152 * ```153 *154 * @see [LocalDateTime.shouldHaveSameYearAs]155 * @see [LocalDateTime.shouldNotHaveSameYearAs]156 */157fun haveSameYear(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {158 override fun test(value: LocalDateTime): MatcherResult =159 MatcherResult(160 value.year == date.year,161 { "$value should have year ${date.year}" },162 {163 "$value should not have year ${date.year}"164 })165}166/**167 * Asserts that this year is the same as [date]'s year168 *169 * Verifies that this year is the same as [date]'s year, ignoring any other fields.170 * 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,171 * and this assertion should pass for this comparison172 *173 * Opposite of [ZonedDateTime.shouldNotHaveSameYearAs]174 *175 * ```176 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))177 * val secondDate = ZonedDateTime.of(1998, 3, 10, 11, 30, 30, 30, ZoneId.of("America/Chicago"))178 *179 * firstDate shouldHaveSameYearAs secondDate // Assertion passes180 *181 *182 * val firstDate = ZonedDateTime.of(2018, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))183 * val secondDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))184 *185 * firstDate shouldHaveSameYearAs secondDate // Assertion fails, 2018 != 1998186 * ```187 */188infix fun ZonedDateTime.shouldHaveSameYearAs(date: ZonedDateTime) = this should haveSameYear(date)189/**190 * Asserts that this year is NOT the same as [date]'s year191 *192 * Verifies that this year isn't the same as [date]'s year, ignoring any other fields.193 * For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo doesn't have the same year as 09/02/2018 10:00:00 -03:00 America/Sao_Paulo,194 * and this assertion should pass for this comparison195 *196 * Opposite of [ZonedDateTime.shouldHaveSameYearAs]197 *198 * ```199 * val firstDate = ZonedDateTime.of(2018, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))200 * val secondDate = ZonedDateTime.of(1998, 2, 9, 19, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))201 *202 * firstDate shouldNotHaveSameYearAs secondDate // Assertion passes203 *204 *205 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))206 * val secondDate = ZonedDateTime.of(1998, 3, 10, 1, 30, 30, 30, ZoneId.of("America/Chicago"))207 *208 * firstDate shouldNotHaveSameYearAs secondDate // Assertion fails, 1998 == 1998, and we expected a difference209 * ```210 */211infix fun ZonedDateTime.shouldNotHaveSameYearAs(date: ZonedDateTime) = this shouldNot haveSameYear(date)212/**213 * Matcher that compares years of ZonedDateTimes214 *215 * Verifies that two ZonedDateTimes have exactly the same year, ignoring any other fields.216 * 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,217 * and the matcher will have a positive result for this comparison218 *219 * ```220 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))221 * val secondDate = ZonedDateTime.of(1998, 3, 10, 11, 30, 30, 30, ZoneId.of("America/Chicago"))222 *223 * firstDate should haveSameYear(secondDate) // Assertion passes224 *225 *226 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))227 * val secondDate = ZonedDateTime.of(2018, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))228 *229 * firstDate shouldNot haveSameYear(secondDate) // Assertion passes230 * ```231 *232 * @see [ZonedDateTime.shouldHaveSameYearAs]233 * @see [ZonedDateTime.shouldNotHaveSameYearAs]234 */235fun haveSameYear(date: ZonedDateTime): Matcher<ZonedDateTime> = object : Matcher<ZonedDateTime> {236 override fun test(value: ZonedDateTime): MatcherResult =237 MatcherResult(238 value.year == date.year,239 { "$value should have year ${date.year}" },240 {241 "$value should not have year ${date.year}"242 })243}244/**245 * Asserts that this year is the same as [date]'s year246 *247 * Verifies that this year is the same as [date]'s year, ignoring any other fields.248 * For example, 09/02/1998 10:00:00 -03:00 has the same year as 10/03/1998 11:30:30 -05:00,249 * and this assertion should pass for this comparison250 *251 * Opposite of [OffsetDateTime.shouldNotHaveSameYearAs]252 *253 * ```254 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))255 * val secondDate = OffsetDateTime.of(1998, 3, 10, 11, 30, 30, 30, ZoneOffset.ofHours(-5))256 *257 * firstDate shouldHaveSameYearAs secondDate // Assertion passes258 *259 *260 * val firstDate = OffsetDateTime.of(2018, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))261 * val secondDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))262 *263 * firstDate shouldHaveSameYearAs secondDate // Assertion fails, 2018 != 1998264 * ```265 */266infix fun OffsetDateTime.shouldHaveSameYearAs(date: OffsetDateTime) = this should haveSameYear(date)267/**268 * Asserts that this year is NOT the same as [date]'s year269 *270 * Verifies that this year isn't the same as [date]'s year, ignoring any other fields.271 * For example, 09/02/1998 10:00:00 -03:00 doesn't have the same year as 09/02/2018 10:00:00 -03:00,272 * and this assertion should pass for this comparison273 *274 * Opposite of [OffsetDateTime.shouldHaveSameYearAs]275 *276 * ```277 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))278 * val secondDate = OffsetDateTime.of(1999, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))279 * firstDate shouldNotHaveSameYearAs secondDate // Assertion passes280 *281 *282 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))283 * val secondDate = OffsetDateTime.of(1998, 3, 10, 11, 30, 30, 0, ZoneOffset.ofHours(-3))284 *285 * firstDate shouldNotHaveSameYearAs secondDate // Assertion fails, 1998 == 1998 and we expected a difference286 *287 * ```288 */289infix fun OffsetDateTime.shouldNotHaveSameYearAs(date: OffsetDateTime) = this shouldNot haveSameYear(date)290/**291 * Matcher that compares years of OffsetDateTimes292 *293 * Verifies that two ZonedDateTimes have exactly the same year, ignoring any other fields.294 * For example, 09/02/1998 10:00:00 -03:00 has the same year as 10/03/1998 11:30:30 -05:00,295 * and the matcher will have a positive result for this comparison296 *297 * ```298 * val firstDate = OffsetDateTime.of(2018, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))299 * val secondDate = OffsetDateTime.of(1998, 2, 9, 19, 0, 0, 0, ZoneOffset.ofHours(-3))300 *301 * firstDate shouldNotHaveSameYearAs secondDate // Assertion passes302 *303 *304 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))305 * val secondDate = OffsetDateTime.of(1998, 3, 10, 1, 30, 30, 30, ZoneOffset.ofHours(-5))306 *307 * firstDate shouldNotHaveSameYearAs secondDate // Assertion fails, 1998 == 1998, and we expected a difference308 * ```309 *310 * @see [OffsetDateTime.shouldHaveSameYearAs]311 * @see [OffsetDateTime.shouldNotHaveSameYearAs]312 */313fun haveSameYear(date: OffsetDateTime): Matcher<OffsetDateTime> = object : Matcher<OffsetDateTime> {314 override fun test(value: OffsetDateTime): MatcherResult =315 MatcherResult(316 value.year == date.year,317 { "$value should have year ${date.year}" },318 {319 "$value should not have year ${date.year}"320 })321}322/**323 * Asserts that this month is the same as [date]'s month324 *325 * Verifies that month year is the same as [date]'s month, ignoring any other fields.326 * For example, 09/02/1998 has the same month as 10/02/2018, and this assertion should pass for this comparison327 *328 * Opposite of [LocalDate.shouldNotHaveSameMonthAs]329 *330 * ```331 * val firstDate = LocalDate.of(1998, 2, 9)332 * val secondDate = LocalDate.of(1998, 3, 10)333 *334 * firstDate should haveSameYear(secondDate) // Assertion passes335 *336 *337 * val firstDate = LocalDate.of(1998, 2, 9)338 * val secondDate = LocalDate.of(2018, 2, 9)339 *340 * firstDate shouldNot haveSameYear(secondDate) // Assertion passes341 * ```342 */343infix fun LocalDate.shouldHaveSameMonthAs(date: LocalDate) = this should haveSameMonth(date)344/**345 * Asserts that this month is NOT the same as [date]'s month346 *347 * Verifies that this month isn't the same as [date]'s month, ignoring any other fields.348 * For example, 09/02/1998 doesn't have the same month as 09/03/1998, and this assertion should pass for this comparison349 *350 * Opposite of [LocalDate.shouldHaveSameMonthAs]351 *352 * ```353 * val firstDate = LocalDate.of(1998, 2, 9)354 * val secondDate = LocalDate.of(2018, 2, 10)355 *356 * firstDate shouldHaveSameMonthAs secondDate // Assertion passes357 *358 *359 * val firstDate = LocalDate.of(1998, 2, 9)360 * val secondDate = LocalDate.of(1998, 3, 9)361 *362 * firstDate shouldHaveSameMonthAs secondDate // Assertion fails, 2 != 3363 * ```364 */365infix fun LocalDate.shouldNotHaveSameMonthAs(date: LocalDate) = this shouldNot haveSameMonth(date)366/**367 * Matcher that compares months of LocalDates368 *369 * Verifies that two dates have exactly the same month, ignoring any other fields.370 * For example, 09/02/1998 has the same month as 10/02/2018, and the matcher will have a positive result for this comparison371 *372 * ```373 * val firstDate = LocalDate.of(1998, 2, 9)374 * val secondDate = LocalDate.of(1998, 3, 9)375 *376 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion passes377 *378 *379 * val firstDate = LocalDate.of(1998, 2, 9)380 * val secondDate = LocalDate.of(2018, 2, 10)381 *382 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion fails, 2 == 2, and we expected a difference383 * ```384 *385 * @see [LocalDate.shouldHaveSameMonthAs]386 * @see [LocalDate.shouldNotHaveSameMonthAs]387 */388fun haveSameMonth(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {389 override fun test(value: LocalDate): MatcherResult =390 MatcherResult(391 value.month == date.month,392 { "$value should have month ${date.month}" },393 {394 "$value should not have month ${date.month}"395 })396}397/**398 * Asserts that this month is the same as [date]'s month399 *400 * Verifies that this month is the same as [date]'s month, ignoring any other fields.401 * For example, 09/02/1998 10:00:00 has the same month as 10/02/2018 11:30:30, and this assertion should pass for this comparison402 *403 * Opposite of [LocalDateTime.shouldNotHaveSameMonthAs]404 *405 * ```406 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)407 * val secondDate = LocalDateTime.of(2018, 2, 10, 10, 0, 0)408 *409 * firstDate should haveSameMonth(secondDate) // Assertion passes410 *411 *412 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)413 * val secondDate = LocalDateTime.of(1998, 3, 9, 10, 0, 0)414 *415 * firstDate shouldNot haveSameMonth(secondDate) // Assertion passes416 * ```417 */418infix fun LocalDateTime.shouldHaveSameMonthAs(date: LocalDateTime) = this should haveSameMonth(date)419/**420 * Asserts that this month is NOT the same as [date]'s month421 *422 * Verifies that this month isn't the same as [date]'s month, ignoring any other fields.423 * For example, 09/02/1998 10:00:00 doesn't have the same month as 09/03/1998 10:00:00, and this assertion should pass for this comparison424 *425 * Opposite of [LocalDateTime.shouldHaveSameMonthAs]426 *427 * ```428 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)429 * val secondDate = LocalDateTime.of(2018, 2, 10, 11, 30, 30)430 *431 * firstDate shouldHaveSameMonthAs secondDate // Assertion passes432 *433 *434 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)435 * val secondDate = LocalDateTime.of(1998, 3, 9, 10, 0, 0)436 *437 * firstDate shouldHaveSameMonthAs secondDate // Assertion fails, 2 != 3438 * ```439 */440infix fun LocalDateTime.shouldNotHaveSameMonthAs(date: LocalDateTime) = this shouldNot haveSameMonth(date)441/**442 * Matcher that compares months of LocalDateTimes443 *444 * Verifies that two DateTimes have exactly the same month, ignoring any other fields.445 * For example, 09/02/1998 10:00:00 has the same month as 10/02/2018 11:30:30, and the matcher will have a positive result for this comparison446 *447 * ```448 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)449 * val secondDate = LocalDateTime.of(1998, 3, 10, 11, 30, 30)450 *451 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion passes452 *453 *454 * val firstDate = LocalDateTime.of(2018, 2, 9, 10, 0, 0)455 * val secondDate = LocalDateTime.of(1998, 2, 10, 1, 30, 30)456 *457 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion fails, 2 == 2, and we expected a difference458 * ```459 *460 * @see [LocalDateTime.shouldHaveSameMonthAs]461 * @see [LocalDateTime.shouldNotHaveSameMonthAs]462 */463fun haveSameMonth(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {464 override fun test(value: LocalDateTime): MatcherResult =465 MatcherResult(466 value.month == date.month,467 { "$value should have month ${date.month}" },468 {469 "$value should not have month ${date.month}"470 })471}472/**473 * Asserts that this month is the same as [date]'s month474 *475 * Verifies that this month is the same as [date]'s month, ignoring any other fields.476 * For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo has the same month as 10/02/2018 11:30:30 -05:00 America/Chicago,477 * and this assertion should pass for this comparison478 *479 * Opposite of [ZonedDateTime.shouldNotHaveSameMonthAs]480 *481 * ```482 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))483 * val secondDate = ZonedDateTime.of(2018, 2, 10, 11, 30, 30, 0, ZoneId.of("America/Sao_Paulo"))484 *485 * firstDate should haveSameMonth(secondDate) // Assertion passes486 *487 *488 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))489 * val secondDate = ZonedDateTime.of(1998, 3, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))490 *491 * firstDate shouldNot haveSameMonth(secondDate) // Assertion passes492 * ```493 */494infix fun ZonedDateTime.shouldHaveSameMonthAs(date: ZonedDateTime) = this should haveSameMonth(date)495/**496 * Asserts that this month is NOT the same as [date]'s month497 *498 * Verifies that this month isn't the same as [date]'s month, ignoring any other fields.499 * For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo doesn't have the same month as 09/03/1998 10:00:00 -03:00 America/Sao_Paulo,500 * and this assertion should pass for this comparison501 *502 * Opposite of [ZonedDateTime.shouldHaveSameMonthAs]503 *504 * ```505 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))506 * val secondDate = ZonedDateTime.of(2018, 2, 10, 11, 30, 30, 30, ZoneId.of("America/Chicago"))507 *508 * firstDate shouldHaveSameMonthAs secondDate // Assertion passes509 *510 *511 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))512 * val secondDate = ZonedDateTime.of(1998, 3, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))513 *514 * firstDate shouldHaveSameMonthAs secondDate // Assertion fails, 2 != 3515 * ```516 */517infix fun ZonedDateTime.shouldNotHaveSameMonthAs(date: ZonedDateTime) = this shouldNot haveSameMonth(date)518/**519 * Matcher that compares months of ZonedDateTimes520 *521 * Verifies that two ZonedDateTimes have exactly the same month, ignoring any other fields.522 * For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo has the same month as 10/02/2018 11:30:30 -05:00 America/Chicago,523 * and the matcher will have a positive result for this comparison524 *525 * ```526 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))527 * val secondDate = ZonedDateTime.of(1998, 3, 9, 19, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))528 *529 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion passes530 *531 *532 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))533 * val secondDate = ZonedDateTime.of(2018, 2, 10, 1, 30, 30, 30, ZoneId.of("America/Chicago"))534 *535 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion fails, 2 == 2, and we expected a difference536 * ```537 *538 * @see [ZonedDateTime.shouldHaveSameMonthAs]539 * @see [ZonedDateTime.shouldNotHaveSameMonthAs]540 */541fun haveSameMonth(date: ZonedDateTime): Matcher<ZonedDateTime> = object : Matcher<ZonedDateTime> {542 override fun test(value: ZonedDateTime): MatcherResult =543 MatcherResult(544 value.month == date.month,545 { "$value should have month ${date.month}" },546 {547 "$value should not have month ${date.month}"548 })549}550/**551 * Asserts that this month is the same as [date]'s month552 *553 * Verifies that this month is the same as [date]'s month, ignoring any other fields.554 * For example, 09/02/1998 10:00:00 -03:00 has the same month as 10/02/2018 11:30:30 -05:00,555 * and this assertion should pass for this comparison556 *557 * Opposite of [OffsetDateTime.shouldNotHaveSameMonthAs]558 *559 * ```560 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))561 * val secondDate = OffsetDateTime.of(2018, 2, 10, 11, 30, 30, 30, ZoneOffset.ofHours(-5))562 *563 * firstDate shouldHaveSameMonthAs secondDate // Assertion passes564 *565 *566 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))567 * val secondDate = OffsetDateTime.of(1998, 3, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))568 *569 * firstDate shouldHaveSameMonthAs secondDate // Assertion fails, 2 != 3570 * ```571 */572infix fun OffsetDateTime.shouldHaveSameMonthAs(date: OffsetDateTime) = this should haveSameMonth(date)573/**574 * Asserts that this month is NOT the same as [date]'s month575 *576 * Verifies that this month isn't the same as [date]'s month, ignoring any other fields.577 * For example, 09/02/1998 10:00:00 -03:00 doesn't have the same month as 09/03/1998 10:00:00 -03:00,578 * and this assertion should pass for this comparison579 *580 * Opposite of [OffsetDateTime.shouldHaveSameMonthAs]581 *582 * ```583 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))584 * val secondDate = OffsetDateTime.of(1998, 3, 9, 19, 0, 0, 0, ZoneOffset.ofHours(-3))585 *586 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion passes587 *588 *589 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))590 * val secondDate = OffsetDateTime.of(2018, 2, 10, 1, 30, 30, 30, ZoneOffset.ofHours(-5))591 *592 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion fails, 2 == 2, and we expected a difference593 * ```594 */595infix fun OffsetDateTime.shouldNotHaveSameMonthAs(date: OffsetDateTime) = this shouldNot haveSameMonth(date)596/**597 * Matcher that compares months of OffsetDateTimes598 *599 * Verifies that two ZonedDateTimes have exactly the same month, ignoring any other fields.600 * For example, 09/02/1998 10:00:00 -03:00 has the same month as 10/02/1998 11:30:30 -05:00,601 * and the matcher will have a positive result for this comparison602 *603 * ```604 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))605 * val secondDate = OffsetDateTime.of(2018, 2, 10, 11, 30, 30, 30, ZoneOffset.ofHours(-5))606 *607 * firstDate should haveSameMonth(secondDate) // Assertion passes608 *609 *610 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))611 * val secondDate = OffsetDateTime.of(1998, 3, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))612 *613 * firstDate shouldNot haveSameMonth(secondDate) // Assertion passes614 * ```615 *616 * @see [OffsetDateTime.shouldHaveSameMonthAs]617 * @see [OffsetDateTime.shouldNotHaveSameMonthAs]618 */619fun haveSameMonth(date: OffsetDateTime): Matcher<OffsetDateTime> = object : Matcher<OffsetDateTime> {620 override fun test(value: OffsetDateTime): MatcherResult =621 MatcherResult(622 value.month == date.month,623 { "$value should have month ${date.month}" },624 {625 "$value should not have month ${date.month}"626 })627}628/**629 * Asserts that this day is the same as [date]'s day630 *631 * Verifies that this day is the same as [date]'s day, ignoring any other fields.632 * For example, 09/02/1998 has the same day as 09/03/2018, and this assertion should pass for this comparison633 *634 * Opposite of [LocalDate.shouldNotHaveSameDayAs]635 *636 * ```637 * val firstDate = LocalDate.of(1998, 2, 9)638 * val secondDate = LocalDate.of(2018, 3, 9)639 *640 * firstDate shouldHaveSameDayAs secondDate // Assertion passes641 *642 *643 * val firstDate = LocalDate.of(1998, 2, 9)644 * val secondDate = LocalDate.of(1998, 2, 10)645 *646 * firstDate shouldHaveSameDayAs secondDate // Assertion fails, 9 != 10647 * ```648 */649infix fun LocalDate.shouldHaveSameDayAs(date: LocalDate) = this should haveSameDay(date)650/**651 * Asserts that this day is NOT the same as [date]'s day652 *653 * Verifies that this day isn't the same as [date]'s day, ignoring any other fields.654 * For example, 09/02/1998 doesn't have the same day as 10/02/1998, and this assertion should pass for this comparison655 *656 * Opposite of [LocalDate.shouldHaveSameDayAs]657 *658 * ```659 * val firstDate = LocalDate.of(1998, 2, 9)660 * val secondDate = LocalDate.of(1998, 2, 10)661 *662 * firstDate shouldNotHaveSameDayAs secondDate // Assertion passes663 *664 *665 * val firstDate = LocalDate.of(1998, 2, 9)666 * val secondDate = LocalDate.of(2018, 3, 9)667 *668 * firstDate shouldNotHaveSameDayAs secondDate // Assertion fails, 9 == 9, and we expected a difference669 * ```670 */671infix fun LocalDate.shouldNotHaveSameDayAs(date: LocalDate) = this shouldNot haveSameDay(date)672/**673 * Matcher that compares days of LocalDates674 *675 * Verifies that two dates have exactly the same day, ignoring any other fields.676 * For example, 09/02/1998 has the same day as 09/03/2018, and the matcher will have a positive result for this comparison677 *678 * ```679 * val firstDate = LocalDate.of(1998, 2, 9)680 * val secondDate = LocalDate.of(2018, 3, 9)681 *682 * firstDate should haveSameDay(secondDate) // Assertion passes683 *684 *685 * val firstDate = LocalDate.of(1998, 2, 9)686 * val secondDate = LocalDate.of(1998, 2, 10)687 *688 * firstDate shouldNot haveSameDay(secondDate) // Assertion passes689 * ```690 *691 * @see [LocalDate.shouldHaveSameDayAs]692 * @see [LocalDate.shouldNotHaveSameDayAs]693 */694fun haveSameDay(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {695 override fun test(value: LocalDate): MatcherResult =696 MatcherResult(697 value.dayOfMonth == date.dayOfMonth,698 { "$value should have day ${date.dayOfMonth} but had ${value.dayOfMonth}" },699 {700 "$value should not have day ${date.dayOfMonth}"701 })702}703/**704 * Asserts that this day is the same as [date]'s day705 *706 * Verifies that this day is the same as [date]'s day, ignoring any other fields.707 * For example, 09/02/1998 10:00:00 has the same day as 09/03/2018 11:30:30, and this assertion should pass for this comparison708 *709 * Opposite of [LocalDateTime.shouldNotHaveSameDayAs]710 *711 * ```712 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)713 * val secondDate = LocalDateTime.of(1998, 3, 9, 11, 30, 30)714 *715 * firstDate shouldHaveSameDayAs secondDate // Assertion passes716 *717 *718 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)719 * val secondDate = LocalDateTime.of(1998, 2, 10, 10, 0, 0)720 *721 * firstDate shouldHaveSameDayAs secondDate // Assertion fails, 9 != 10722 * ```723 */724infix fun LocalDateTime.shouldHaveSameDayAs(date: LocalDateTime) = this should haveSameDay(date)725/**726 * Asserts that this day is NOT the same as [date]'s day727 *728 * Verifies that this year isn't the same as [date]'s day, ignoring any other fields.729 * For example, 09/02/1998 10:00:00 doesn't have the same day as 10/02/1998 10:00:00, and this assertion should pass for this comparison730 *731 * Opposite of [LocalDateTime.shouldHaveSameDayAs]732 *733 * ```734 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)735 * val secondDate = LocalDateTime.of(1998, 2, 10, 10, 0, 0)736 *737 * firstDate shouldNotHaveSameDayAs secondDate // Assertion passes738 *739 *740 * val firstDate = LocalDateTime.of(2018, 2, 9, 10, 0, 0)741 * val secondDate = LocalDateTime.of(1998, 3, 9, 11, 30, 30)742 *743 * firstDate shouldNotHaveSameDayAs secondDate // Assertion fails, 9 == 9, and we expected a difference744 * ```745 */746infix fun LocalDateTime.shouldNotHaveSameDayAs(date: LocalDateTime) = this shouldNot haveSameDay(date)747/**748 * Matcher that compares days of LocalDateTimes749 *750 * Verifies that two DateTimes have exactly the same day, ignoring any other fields.751 * 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 comparison752 *753 * ```754 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)755 * val secondDate = LocalDateTime.of(2018, 3, 9, 11, 30, 30)756 *757 * firstDate should haveSameDay(secondDate) // Assertion passes758 *759 *760 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)761 * val secondDate = LocalDateTime.of(1998, 2, 10, 10, 0, 0)762 *763 * firstDate shouldNot haveSameDay(secondDate) // Assertion passes764 * ```765 *766 * @see [LocalDateTime.shouldHaveSameDayAs]767 * @see [LocalDateTime.shouldNotHaveSameDayAs]768 */769fun haveSameDay(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {770 override fun test(value: LocalDateTime): MatcherResult =771 MatcherResult(772 value.dayOfMonth == date.dayOfMonth,773 { "$value should have day ${date.dayOfMonth} but had ${value.dayOfMonth}" },774 {775 "$value should not have day ${date.dayOfMonth}"776 })777}778/**779 * Asserts that this day is the same as [date]'s day780 *781 * Verifies that this day is the same as [date]'s day, ignoring any other fields.782 * 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,783 * and this assertion should pass for this comparison784 *785 * Opposite of [ZonedDateTime.shouldNotHaveSameDayAs]786 *787 * ```788 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))789 * val secondDate = ZonedDateTime.of(2018, 3, 9, 11, 30, 30, 30, ZoneId.of("America/Chicago"))790 *791 * firstDate shouldHaveSameDayAs secondDate // Assertion passes792 *793 *794 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))795 * val secondDate = ZonedDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))796 *797 * firstDate shouldHaveSameDayAs secondDate // Assertion fails, 9 != 10798 * ```799 */800infix fun ZonedDateTime.shouldHaveSameDayAs(date: ZonedDateTime) = this should haveSameDay(date)801/**802 * Asserts that this day is NOT the same as [date]'s day803 *804 * Verifies that this day isn't the same as [date]'s day, ignoring any other fields.805 * For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo doesn't have the same day as 10/02/1998 10:00:00 -03:00 America/Sao_Paulo,806 * and this assertion should pass for this comparison807 *808 * Opposite of [ZonedDateTime.shouldHaveSameDayAs]809 *810 * ```811 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))812 * val secondDate = ZonedDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))813 *814 * firstDate shouldNotHaveSameDayAs secondDate // Assertion passes815 *816 *817 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))818 * val secondDate = ZonedDateTime.of(2018, 3, 9, 11, 30, 30, 30, ZoneId.of("America/Chicago"))819 *820 * firstDate shouldNotHaveSameDayAs secondDate // Assertion fails, 9 == 9, and we expected a difference821 * ```822 */823infix fun ZonedDateTime.shouldNotHaveSameDayAs(date: ZonedDateTime) = this shouldNot haveSameDay(date)824/**825 * Matcher that compares days of ZonedDateTimes826 *827 * Verifies that two ZonedDateTimes have exactly the same day, ignoring any other fields.828 * 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,829 * and the matcher will have a positive result for this comparison830 *831 * ```832 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))833 * val secondDate = ZonedDateTime.of(2018, 3, 9, 11, 30, 30, 30, ZoneId.of("America/Chicago"))834 *835 * firstDate should haveSameDay(secondDate) // Assertion passes836 *837 *838 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))839 * val secondDate = ZonedDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))840 *841 * firstDate shouldNot haveSameDay(secondDate) // Assertion passes842 * ```843 *844 * @see [ZonedDateTime.shouldHaveSameDayAs]845 * @see [ZonedDateTime.shouldNotHaveSameDayAs]846 */847fun haveSameDay(date: ZonedDateTime): Matcher<ZonedDateTime> = object : Matcher<ZonedDateTime> {848 override fun test(value: ZonedDateTime): MatcherResult =849 MatcherResult(850 value.dayOfMonth == date.dayOfMonth,851 { "$value should have day ${date.dayOfMonth} but had ${value.dayOfMonth}" },852 {853 "$value should not have day ${date.dayOfMonth}"854 })855}856/**857 * Asserts that this day is the same as [date]'s day858 *859 * Verifies that this day is the same as [date]'s day, ignoring any other fields.860 * For example, 09/02/1998 10:00:00 -03:00 has the day year as 09/02/1998 11:30:30 -05:00,861 * and this assertion should pass for this comparison862 *863 * Opposite of [OffsetDateTime.shouldNotHaveSameDayAs]864 *865 * ```866 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))867 * val secondDate = OffsetDateTime.of(2018, 3, 9, 11, 30, 30, 30, ZoneOffset.ofHours(-5))868 *869 * firstDate shouldHaveSameDayAs secondDate // Assertion passes870 *871 *872 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))873 * val secondDate = OffsetDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneOffset.ofHours(-3))874 *875 * firstDate shouldHaveSameDayAs secondDate // Assertion fails, 9 != 12876 * ```877 */878infix fun OffsetDateTime.shouldHaveSameDayAs(date: OffsetDateTime) = this should haveSameDay(date)879/**880 * Asserts that this day is NOT the same as [date]'s day881 *882 * Verifies that this day isn't the same as [date]'s day, ignoring any other fields.883 * For example, 09/02/1998 10:00:00 -03:00 doesn't have the same day as 10/02/1998 10:00:00 -03:00,884 * and this assertion should pass for this comparison885 *886 * Opposite of [OffsetDateTime.shouldHaveSameDayAs]887 *888 * ```889 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))890 * val secondDate = OffsetDateTime.of(1998, 2, 10, 19, 0, 0, 0, ZoneOffset.ofHours(-3))891 *892 * firstDate shouldNotHaveSameDayAs secondDate // Assertion passes893 *894 *895 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))896 * val secondDate = OffsetDateTime.of(2018, 3, 9, 1, 30, 30, 30, ZoneOffset.ofHours(-5))897 *898 * firstDate shouldNotHaveSameDayAs secondDate // Assertion fails, 9 == 9, and we expected a difference899 * ```900 */901infix fun OffsetDateTime.shouldNotHaveSameDayAs(date: OffsetDateTime) = this shouldNot haveSameDay(date)902/**903 * Matcher that compares days of OffsetDateTimes904 *905 * Verifies that two ZonedDateTimes have exactly the same day, ignoring any other fields.906 * For example, 09/02/1998 10:00:00 -03:00 has the same day as 09/03/2018 11:30:30 -05:00,907 * and the matcher will have a positive result for this comparison908 *909 * ```910 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))911 * val secondDate = OffsetDateTime.of(2018, 3, 9, 11, 30, 30, 30, ZoneOffset.ofHours(-5))912 *913 * firstDate should haveSameDay(secondDate) // Assertion passes914 *915 *916 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))917 * val secondDate = OffsetDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneOffset.ofHours(-3))918 *919 * firstDate shouldNot haveSameDay(secondDate) // Assertion passes920 * ```921 *922 * @see [OffsetDateTime.shouldHaveSameDayAs]923 * @see [OffsetDateTime.shouldNotHaveSameDayAs]924 */925fun haveSameDay(date: OffsetDateTime): Matcher<OffsetDateTime> = object : Matcher<OffsetDateTime> {926 override fun test(value: OffsetDateTime): MatcherResult =927 MatcherResult(928 value.dayOfMonth == date.dayOfMonth,929 { "$value should have day ${date.dayOfMonth} but had ${value.dayOfMonth}" },930 {931 "$value should not have day ${date.dayOfMonth}"932 })933}934/**935 * Asserts that this is before [date]936 *937 * Verifies that this is before [date], comparing year, month and day.938 * For example, 09/02/1998 is before 10/02/1998, and this assertion should pass for this comparison.939 *940 * Opposite of [LocalDate.shouldNotBeBefore]941 *942 * ```943 * val firstDate = LocalDate.of(1998, 2, 9)944 * val secondDate = LocalDate.of(1998, 2, 10)945 *946 * firstDate shouldBeBefore secondDate // Assertion passes947 *948 *949 * val firstDate = LocalDate.of(1998, 2, 10)950 * val secondDate = LocalDate.of(1998, 2, 9)951 *952 * firstDate shouldBeBefore secondDate // Assertion fails, 10/02/1998 is not before 09/02/1998 as expected.953 * ```954 *955 * @see LocalDate.shouldNotBeAfter956 */957infix fun LocalDate.shouldBeBefore(date: LocalDate) = this should before(date)958/**959 * Asserts that this is NOT before [date]960 *961 * Verifies that this is not before [date], comparing year, month and day.962 * For example, 10/02/1998 is not before 09/02/1998, and this assertion should pass for this comparison.963 *964 * Opposite of [LocalDate.shouldBeBefore]965 *966 * ```967 * val firstDate = LocalDate.of(1998, 2, 10)968 * val secondDate = LocalDate.of(1998, 2, 9)969 *970 * firstDate shouldNotBeBefore secondDate // Assertion passes971 * val firstDate = LocalDate.of(1998, 2, 9)972 * val secondDate = LocalDate.of(1998, 2, 10)973 *974 * firstDate shouldNotBeBefore secondDate // Assertion fails, 09/02/1998 is before 10/02/1998, and we expected the opposite.975 * ```976 *977 * @see LocalDate.shouldBeAfter978 */979infix fun LocalDate.shouldNotBeBefore(date: LocalDate) = this shouldNot before(date)980/**981 * Matcher that compares two LocalDates and checks whether one is before the other982 *983 * Verifies that two LocalDates occurs in a certain order, checking that one happened before the other.984 * For example, 09/02/1998 is before 10/02/1998, and the matcher will have a positive result for this comparison985 *986 * ```987 * val firstDate = LocalDate.of(1998, 2, 9)988 * val secondDate = LocalDate.of(1998, 2, 10)989 *990 * firstDate shouldBe before(secondDate) // Assertion passes991 *992 *993 * val firstDate = LocalDate.of(1998, 2, 10)994 * val secondDate = LocalDate.of(1998, 2, 9)995 *996 * firstDate shouldNotBe before(secondDate) // Assertion passes997 * ```998 *999 * @see LocalDate.shouldBeBefore1000 * @see LocalDate.shouldNotBeBefore1001 */1002fun before(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {1003 override fun test(value: LocalDate): MatcherResult =1004 MatcherResult(1005 value.isBefore(date),1006 { "$value should be before $date" },1007 { "$value should not be before $date" })1008}1009/**1010 * Asserts that this is before [date]1011 *1012 * Verifies that this is before [date], comparing every field in the LocalDateTime.1013 * For example, 09/02/1998 00:00:00 is before 09/02/1998 00:00:01, and this assertion should pass for this comparison.1014 *1015 * Opposite of [LocalDateTime.shouldNotBeBefore]1016 *1017 * ```1018 * val firstDate = LocalDateTime.of(1998, 2, 9, 0, 0, 0)1019 * val secondDate = LocalDateTime.of(1998, 2, 9, 0, 0, 1)1020 *1021 * firstDate shouldBeBefore secondDate // Assertion passes1022 *1023 *1024 * val firstDate = LocalDateTime.of(1998, 2, 9, 0, 0, 1)1025 * val secondDate = LocalDateTime.of(1998, 2, 9, 0, 0, 0)1026 *1027 * firstDate shouldBeBefore secondDate // Assertion fails, firstDate is one second after secondDate1028 * ```1029 *1030 * @see LocalDateTime.shouldNotBeAfter1031 */1032infix fun LocalDateTime.shouldBeBefore(date: LocalDateTime) = this should before(date)1033/**1034 * Asserts that this is NOT before [date]1035 *1036 * Verifies that this is not before [date], comparing every field in the LocalDateTime.1037 * For example, 09/02/1998 00:00:01 is not before 09/02/1998 00:00:00, and this assertion should pass for this comparison.1038 *1039 * Opposite of [LocalDateTime.shouldBeBefore]1040 *1041 * ```1042 * val firstDate = LocalDateTime.of(1998, 2, 9, 0, 0, 1)1043 * val secondDate = LocalDateTime.of(1998, 2, 9, 0, 0, 0)1044 *1045 * firstDate shouldNotBeBefore secondDate // Assertion passes1046 *1047 *1048 * val firstDate = LocalDateTime.of(1998, 2, 9, 0, 0, 0)1049 * val secondDate = LocalDateTime.of(1998, 2, 9, 0, 0, 1)1050 *1051 * firstDate shouldNotBeBefore secondDate // Assertion fails, firstDate is one second before secondDate and we didn't expect it1052 * ```1053 *1054 * @see LocalDateTime.shouldBeAfter1055 */1056infix fun LocalDateTime.shouldNotBeBefore(date: LocalDateTime) = this shouldNot before(date)1057/**1058 * Matcher that compares two LocalDateTimes and checks whether one is before the other1059 *1060 * Verifies that two LocalDateTimes occurs in a certain order, checking that one happened before the other.1061 * For example, 09/02/1998 00:00:00 is before 09/02/1998 00:00:01, and the matcher will have a positive result for this comparison1062 *1063 * ```1064 * val firstDate = LocalDateTime.of(1998, 2, 9, 0, 0, 0)1065 * val secondDate = LocalDateTime.of(1998, 2, 9, 0, 0, 1)1066 *1067 * firstDate shouldBe before(secondDate) // Assertion passes1068 *1069 *1070 * val firstDate = LocalDateTime.of(1998, 2, 9, 0, 0, 1)1071 * val secondDate = LocalDateTime.of(1998, 2, 9, 0, 0, 0)1072 *1073 * firstDate shouldNotBe before(secondDate) // Assertion passes1074 * ```1075 *1076 * @see LocalDateTime.shouldBeBefore1077 * @see LocalDateTime.shouldNotBeBefore1078 */1079fun before(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {1080 override fun test(value: LocalDateTime): MatcherResult =1081 MatcherResult(1082 value.isBefore(date),1083 { "$value should be before $date" },1084 { "$value should not be before $date" })1085}1086/**1087 * Asserts that this is before [date]1088 *1089 * Verifies that this is before [date], comparing every field in the ZonedDateTime.1090 * For example, 09/02/1998 00:00:00 -03:00 America/Sao_Paulo is before 09/02/1998 00:00:01 -03:00 America/Sao_Paulo,1091 * and this assertion should pass for this comparison.1092 *1093 * Opposite of [ZonedDateTime.shouldNotBeBefore]1094 *1095 * ```1096 * val firstDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1097 * val secondDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneId.of("America/Sao_Paulo"))1098 *1099 * firstDate shouldBeBefore secondDate // Assertion passes1100 *1101 *1102 * val firstDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneId.of("America/Sao_Paulo"))1103 * val secondDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1104 *1105 * firstDate shouldBeBefore secondDate // Assertion fails, firstDate is one second after secondDate1106 * ```1107 *1108 * @see ZonedDateTime.shouldNotBeAfter1109 */1110infix fun ZonedDateTime.shouldBeBefore(date: ZonedDateTime) = this should before(date)1111/**1112 * Asserts that this is NOT before [date]1113 *1114 * Verifies that this is not before [date], comparing every field in the ZonedDateTime.1115 * For example, 09/02/1998 00:00:01 -03:00 America/Sao_Paulo is not before 09/02/1998 00:00:00 -03:00 America/Sao_Paulo,1116 * and this assertion should pass for this comparison.1117 *1118 * Opposite of [ZonedDateTime.shouldBeBefore]1119 *1120 * ```1121 * val firstDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneId.of("America/Sao_Paulo"))1122 * val secondDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1123 *1124 * firstDate shouldNotBeBefore secondDate // Assertion passes1125 *1126 *1127 * val firstDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1128 * val secondDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneId.of("America/Sao_Paulo"))1129 *1130 * firstDate shouldNotBeBefore secondDate // Assertion fails, firstDate is one second before secondDate and we didn't expect it1131 * ```1132 *1133 * @see ZonedDateTime.shouldBeAfter1134 */1135infix fun ZonedDateTime.shouldNotBeBefore(date: ZonedDateTime) = this shouldNot before(date)1136/**1137 * Matcher that compares two ZonedDateTimes and checks whether one is before the other1138 *1139 * Verifies that two ZonedDateTimes occurs in a certain order, checking that one happened before the other.1140 * For example, 09/02/1998 00:00:00 -03:00 America/Sao_Paulo is before 09/02/1998 00:00:01 -03:00 America/Sao_Paulo,1141 * and the matcher will have a positive result for this comparison1142 *1143 * ```1144 * val firstDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1145 * val secondDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneId.of("America/Sao_Paulo"))1146 *1147 * firstDate shouldBe before(secondDate) // Assertion passes1148 *1149 *1150 * val firstDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneId.of("America/Sao_Paulo"))1151 * val secondDate = ZonedDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1152 *1153 * firstDate shouldNotBe before(secondDate) // Assertion passes1154 * ```1155 *1156 * @see ZonedDateTime.shouldBeBefore1157 * @see ZonedDateTime.shouldNotBeBefore1158 */1159fun before(date: ZonedDateTime): Matcher<ZonedDateTime> = object : Matcher<ZonedDateTime> {1160 override fun test(value: ZonedDateTime): MatcherResult =1161 MatcherResult(1162 value.isBefore(date),1163 { "$value should be before $date" },1164 { "$value should not be before $date" })1165}1166/**1167 * Asserts that this is before [date]1168 *1169 * Verifies that this is before [date], comparing every field in the OffsetDateTime.1170 * For example, 09/02/1998 00:00:00 -03:00 is before 09/02/1998 00:00:01 -03:00,1171 * and this assertion should pass for this comparison.1172 *1173 * Opposite of [OffsetDateTime.shouldNotBeBefore]1174 *1175 * ```1176 * val firstDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneOffset.ofHours(-3))1177 * val secondDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneOffset.ofHours(-3))1178 *1179 * firstDate shouldBeBefore secondDate // Assertion passes1180 *1181 *1182 * val firstDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneOffset.ofHours(-3))1183 * val secondDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneOffset.ofHours(-3))1184 *1185 * firstDate shouldBeBefore secondDate // Assertion fails, firstDate is one second after secondDate1186 * ```1187 *1188 * @see OffsetDateTime.shouldNotBeAfter1189 */1190infix fun OffsetDateTime.shouldBeBefore(date: OffsetDateTime) = this should before(date)1191/**1192 * Asserts that this is NOT before [date]1193 *1194 * Verifies that this is not before [date], comparing every field in the OffsetDateTime.1195 * For example, 09/02/1998 00:00:01 -03:00 is not before 09/02/1998 00:00:00 -03:00,1196 * and this assertion should pass for this comparison.1197 *1198 * Opposite of [OffsetDateTime.shouldBeBefore]1199 *1200 * ```1201 * val firstDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneOffset.ofHours(-3))1202 * val secondDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneOffset.ofHours(-3))1203 *1204 * firstDate shouldNotBeBefore secondDate // Assertion passes1205 *1206 *1207 * val firstDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneOffset.ofHours(-3))1208 * val secondDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneOffset.ofHours(-3))1209 *1210 * firstDate shouldNotBeBefore secondDate // Assertion fails, firstDate is one second before secondDate and we didn't expect it1211 * ```1212 *1213 * @see OffsetDateTime.shouldBeAfter1214 */1215infix fun OffsetDateTime.shouldNotBeBefore(date: OffsetDateTime) = this shouldNot before(date)1216/**1217 * Matcher that compares two OffsetDateTimes and checks whether one is before the other1218 *1219 * Verifies that two OffsetDateTimes occurs in a certain order, checking that one happened before the other.1220 * For example, 09/02/1998 00:00:00 -03:00 is before 09/02/1998 00:00:01 -03:00,1221 * and the matcher will have a positive result for this comparison1222 *1223 * ```1224 * val firstDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneOffset.ofHours(-3))1225 * val secondDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneOffset.ofHours(-3))1226 *1227 * firstDate shouldBe before(secondDate) // Assertion passes1228 *1229 *1230 * val firstDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 1, 0, ZoneOffset.ofHours(-3))1231 * val secondDate = OffsetDateTime.of(1998, 2, 9, 0, 0, 0, 0, ZoneOffset.ofHours(-3))1232 *1233 * firstDate shouldNotBe before(secondDate) // Assertion passes1234 * ```1235 *1236 * @see OffsetDateTime.shouldBeBefore1237 * @see OffsetDateTime.shouldNotBeBefore1238 */1239fun before(date: OffsetDateTime): Matcher<OffsetDateTime> = object : Matcher<OffsetDateTime> {1240 override fun test(value: OffsetDateTime): MatcherResult =1241 MatcherResult(1242 value.isBefore(date),1243 { "$value should be before $date" },1244 { "$value should not be before $date" })1245}1246/**1247 * Asserts that this is after [date]1248 *1249 * Verifies that this is after [date], comparing year, month and day.1250 * For example, 09/02/1998 is after 08/02/1998, and this assertion should pass for this comparison.1251 *1252 * Opposite of [LocalDate.shouldNotBeAfter]1253 *1254 * ```1255 * val firstDate = LocalDate.of(1998, 2, 9)1256 * val secondDate = LocalDate.of(1998, 2, 8)1257 *1258 * firstDate shouldBeAfter secondDate // Assertion passes1259 *1260 *1261 * val firstDate = LocalDate.of(1998, 2, 9)1262 * val secondDate = LocalDate.of(1998, 2, 10)1263 *1264 * firstDate shouldBeAfter secondDate // Assertion fails, firstDate is NOT after secondDate1265 * ```1266 *1267 * @see LocalDate.shouldNotBeBefore1268 */1269infix fun LocalDate.shouldBeAfter(date: LocalDate) = this should after(date)1270/**1271 * Asserts that this is NOT after [date]1272 *1273 * Verifies that this is not after [date], comparing year, month and day.1274 * For example, 09/02/1998 is not after 10/02/1998, and this assertion should pass for this comparison.1275 *1276 * Opposite of [LocalDate.shouldBeAfter]1277 *1278 * ```1279 * val firstDate = LocalDate.of(1998, 2, 9)1280 * val secondDate = LocalDate.of(1998, 2, 10)1281 *1282 * firstDate shouldNotBeAfter secondDate // Assertion passes1283 *1284 *1285 * val firstDate = LocalDate.of(1998, 2, 10)1286 * val secondDate = LocalDate.of(1998, 2, 9)1287 *1288 * firstDate shouldNotBeAfter secondDate // Assertion fails, first date IS after secondDate1289 * ```1290 *1291 * @see LocalDate.shouldBeBefore1292 */1293infix fun LocalDate.shouldNotBeAfter(date: LocalDate) = this shouldNot after(date)1294/**1295 * Matcher that compares two LocalDates and checks whether one is after the other1296 *1297 * Verifies that two LocalDates occurs in a certain order, checking that one happened after the other.1298 * For example, 10/02/1998 is after 09/02/1998, and the matcher will have a positive result for this comparison1299 *1300 * ```1301 * val firstDate = LocalDate.of(1998, 2, 9)1302 * val secondDate = LocalDate.of(1998, 2, 8)1303 *1304 * firstDate shouldBe after(secondDate ) // Assertion passes1305 *1306 *1307 * val firstDate = LocalDate.of(1998, 2, 9)1308 * val secondDate = LocalDate.of(1998, 2, 10)1309 *1310 * firstDate shouldNotBe after(secondDate) // Assertion passes1311 * ```1312 *1313 * @see LocalDate.shouldBeAfter1314 * @see LocalDate.shouldNotBeAfter1315 */1316fun after(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {1317 override fun test(value: LocalDate): MatcherResult =1318 MatcherResult(1319 value.isAfter(date),1320 { "$value should be after $date" },1321 { "$value should not be after $date" })1322}1323/**1324 * Asserts that this is after [date]1325 *1326 * Verifies that this is after [date], comparing all fields in LocalDateTime.1327 * For example, 09/02/1998 10:00:00 is after 09/02/1998 09:00:00, and this assertion should pass for this comparison.1328 *1329 * Opposite of [LocalDateTime.shouldNotBeAfter]1330 *1331 * ```1332 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1333 * val secondDate = LocalDateTime.of(1998, 2, 8, 10, 0, 0)1334 *1335 * firstDate shouldBeAfter secondDate // Assertion passes1336 *1337 *1338 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1339 * val secondDate = LocalDateTime.of(1998, 2, 10, 10, 0, 0)1340 *1341 * firstDate shouldBeAfter secondDate // Assertion fails, firstDate is NOT after secondDate1342 * ```1343 *1344 * @see LocalDateTime.shouldNotBeBefore1345 */1346infix fun LocalDateTime.shouldBeAfter(date: LocalDateTime) = this should after(date)1347/**1348 * Asserts that this is NOT after [date]1349 *1350 * Verifies that this is not after [date], comparing all fields in LocalDateTime.1351 * For example, 09/02/1998 09:00:00 is not after 09/02/1998 10:00:00, and this assertion should pass for this comparison.1352 *1353 * Opposite of [LocalDateTime.shouldBeAfter]1354 *1355 * ```1356 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1357 * val secondDate = LocalDateTime.of(1998, 2, 10, 10, 0, 0)1358 *1359 * firstDate shouldNotBeAfter secondDate // Assertion passes1360 *1361 *1362 * val firstDate = LocalDateTime.of(1998, 2, 10, 10, 0, 0)1363 * val secondDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1364 *1365 * firstDate shouldNotBeAfter secondDate // Assertion fails, first date IS after secondDate1366 * ```1367 *1368 * @see LocalDateTime.shouldBeBefore1369 */1370infix fun LocalDateTime.shouldNotBeAfter(date: LocalDateTime) = this shouldNot after(date)1371/**1372 * Matcher that compares two LocalDateTimes and checks whether one is after the other1373 *1374 * Verifies that two LocalDateTimes occurs in a certain order, checking that one happened after the other.1375 * For example, 09/02/1998 10:00:00 is after 09/02/1998 09:00:00, and the matcher will have a positive result for this comparison1376 *1377 * ```1378 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1379 * val secondDate = LocalDateTime.of(1998, 2, 8, 10, 0, 0)1380 *1381 * firstDate shouldBe after(secondDate ) // Assertion passes1382 *1383 *1384 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1385 * val secondDate = LocalDateTime.of(1998, 2, 10, 10, 0, 0)1386 *1387 * firstDate shouldNotBe after(secondDate) // Assertion passes1388 * ```1389 *1390 * @see LocalDateTime.shouldBeAfter1391 * @see LocalDateTime.shouldNotBeAfter1392 */1393fun after(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {1394 override fun test(value: LocalDateTime): MatcherResult =1395 MatcherResult(1396 value.isAfter(date),1397 { "$value should be after $date" },1398 { "$value should not be after $date" })1399}1400/**1401 * Asserts that this is after [date]1402 *1403 * Verifies that this is after [date], comparing all fields in ZonedDateTime.1404 * For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo is after 09/02/1998 09:00:00 -03:00 America/Sao_Paulo,1405 * and this assertion should pass for this comparison.1406 *1407 * Opposite of [ZonedDateTime.shouldNotBeAfter]1408 *1409 * ```1410 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1411 * val secondDate = ZonedDateTime.of(1998, 2, 8, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1412 *1413 * firstDate shouldBeAfter secondDate // Assertion passes1414 *1415 *1416 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1417 * val secondDate = ZonedDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1418 *1419 * firstDate shouldBeAfter secondDate // Assertion fails, firstDate is NOT after secondDate1420 * ```1421 *1422 * @see ZonedDateTime.shouldNotBeBefore1423 */1424infix fun ZonedDateTime.shouldBeAfter(date: ZonedDateTime) = this should after(date)1425/**1426 * Asserts that this is NOT after [date]1427 *1428 * Verifies that this is not after [date], comparing all fields in ZonedDateTime.1429 * For example, 09/02/1998 09:00:00 -03:00 America/Sao_Paulo is not after 09/02/1998 10:00:00 -03:00 America/Sao_Paulo,1430 * and this assertion should pass for this comparison.1431 *1432 * Opposite of [ZonedDateTime.shouldBeAfter]1433 *1434 * ```1435 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1436 * val secondDate = ZonedDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1437 *1438 * firstDate shouldNotBeAfter secondDate // Assertion passes1439 *1440 *1441 * val firstDate = ZonedDateTime.of(1998, 2, 10, 10, 0, 0, ZoneId.of("America/Sao_Paulo"))1442 * val secondDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, ZoneId.of("America/Sao_Paulo"))1443 *1444 * firstDate shouldNotBeAfter secondDate // Assertion fails, first date IS after secondDate1445 * ```1446 *1447 * @see ZonedDateTime.shouldBeBefore1448 */1449infix fun ZonedDateTime.shouldNotBeAfter(date: ZonedDateTime) = this shouldNot after(date)1450/**1451 * Matcher that compares two ZonedDateTimes and checks whether one is after the other1452 *1453 * Verifies that two ZonedDateTimes occurs in a certain order, checking that one happened after the other.1454 * For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo is after 09/02/1998 09:00:00 -03:00 America/Sao_Paulo,1455 * and the matcher will have a positive result for this comparison1456 *1457 * ```1458 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1459 * val secondDate = ZonedDateTime.of(1998, 2, 8, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1460 *1461 * firstDate shouldBe after(secondDate ) // Assertion passes1462 *1463 *1464 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1465 * val secondDate = ZonedDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))1466 *1467 * firstDate shouldNotBe after(secondDate) // Assertion passes1468 * ```1469 *1470 * @see ZonedDateTime.shouldBeAfter1471 * @see ZonedDateTime.shouldNotBeAfter1472 */1473fun after(date: ZonedDateTime): Matcher<ZonedDateTime> = object : Matcher<ZonedDateTime> {1474 override fun test(value: ZonedDateTime): MatcherResult =1475 MatcherResult(1476 value.isAfter(date),1477 { "$value should be after $date" },1478 { "$value should not be after $date" })1479}1480/**1481 * Asserts that this is after [date]1482 *1483 * Verifies that this is after [date], comparing all fields in OffsetDateTime.1484 * For example, 09/02/1998 10:00:00 -03:00 is after 09/02/1998 09:00:00 -03:00,1485 * and this assertion should pass for this comparison.1486 *1487 * Opposite of [OffsetDateTime.shouldNotBeAfter]1488 *1489 * ```1490 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1491 * val secondDate = OffsetDateTime.of(1998, 2, 8, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1492 *1493 * firstDate shouldBeAfter secondDate // Assertion passes1494 *1495 *1496 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1497 * val secondDate = OffsetDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1498 *1499 * firstDate shouldBeAfter secondDate // Assertion fails, firstDate is NOT after secondDate1500 * ```1501 *1502 * @see OffsetDateTime.shouldNotBeBefore1503 */1504infix fun OffsetDateTime.shouldBeAfter(date: OffsetDateTime) = this should after(date)1505/**1506 * Asserts that this is NOT after [date]1507 *1508 * Verifies that this is not after [date], comparing all fields in OffsetDateTime.1509 * For example, 09/02/1998 09:00:00 -03:00 is not after 09/02/1998 10:00:00 -03:00,1510 * and this assertion should pass for this comparison.1511 *1512 * Opposite of [OffsetDateTime.shouldBeAfter]1513 *1514 * ```1515 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1516 * val secondDate = OffsetDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1517 *1518 * firstDate shouldNotBeAfter secondDate // Assertion passes1519 *1520 *1521 * val firstDate = OffsetDateTime.of(1998, 2, 10, 10, 0, 0, ZoneOffset.ofHours(-3))1522 * val secondDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, ZoneOffset.ofHours(-3))1523 *1524 * firstDate shouldNotBeAfter secondDate // Assertion fails, first date IS after secondDate1525 * ```1526 *1527 * @see OffsetDateTime.shouldBeBefore1528 */1529infix fun OffsetDateTime.shouldNotBeAfter(date: OffsetDateTime) = this shouldNot after(date)1530/**1531 * Matcher that compares two OffsetDateTimes and checks whether one is after the other1532 *1533 * Verifies that two OffsetDateTimes occurs in a certain order, checking that one happened after the other.1534 * For example, 09/02/1998 10:00:00 -03:00 is after 09/02/1998 09:00:00 -03:00,1535 * and the matcher will have a positive result for this comparison1536 *1537 * ```1538 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1539 * val secondDate = OffsetDateTime.of(1998, 2, 8, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1540 *1541 * firstDate shouldBe after(secondDate ) // Assertion passes1542 *1543 *1544 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1545 * val secondDate = OffsetDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1546 *1547 * firstDate shouldNotBe after(secondDate) // Assertion passes1548 * ```1549 *1550 * @see OffsetDateTime.shouldBeAfter1551 * @see OffsetDateTime.shouldNotBeAfter1552 */1553fun after(date: OffsetDateTime): Matcher<OffsetDateTime> = object : Matcher<OffsetDateTime> {1554 override fun test(value: OffsetDateTime): MatcherResult =1555 MatcherResult(1556 value.isAfter(date),1557 { "$value should be after $date" },1558 { "$value should not be after $date" })1559}1560/**1561 * Asserts that this is within [period] of [date]1562 *1563 * Verifies that this is within [period] of [date].1564 * For example, 09/02/1998 is within 3 days of 10/02/1998, and this assertion should pass for this comparison.1565 *1566 * Opposite of [LocalDate.shouldNotBeWithin]1567 *1568 * ```1569 * val firstDate = LocalDate.of(1998, 2, 9)1570 * val secondDate = LocalDate.of(1998, 2, 10)1571 *1572 * firstDate.shouldBeWithin(Period.ofDays(3), secondDate) // Assertion passes1573 *1574 *1575 * val firstDate = LocalDate.of(1998, 2, 9)1576 * val secondDate = LocalDate.of(1998, 2, 25)1577 *1578 * firstDate.shouldBeWithin(Period.ofDays(3), secondDate) // Assertion fails, firstDate is not within 3 days of secondDate1579 * ```1580 */1581fun LocalDate.shouldBeWithin(period: Period, date: LocalDate) = this should within(period, date)1582/**1583 * Asserts that this is NOT within [period] of [date]1584 *1585 * Verifies that this is not within [period] of [date].1586 * For example, 09/02/1998 is not within 3 days of 25/02/1998, and this assertion should pass for this comparison.1587 *1588 * Opposite of [LocalDate.shouldBeWithin]1589 *1590 * ```1591 * val firstDate = LocalDate.of(1998, 2, 9)1592 * val secondDate = LocalDate.of(1998, 2, 25)1593 *1594 * firstDate.shouldNotBeWithin(Period.ofDays(3), secondDate) // Assertion passes1595 *1596 *1597 * val firstDate = LocalDate.of(1998, 2, 9)1598 * val secondDate = LocalDate.of(1998, 2, 10)1599 *1600 * firstDate.shouldNotBeWithin(Period.ofDays(3), secondDate) // Assertion fails, firstDate is within 3 days of secondDate, and we expected not to1601 * ```1602 */1603fun LocalDate.shouldNotBeWithin(period: Period, date: LocalDate) = this shouldNot within(period, date)1604/**1605 * Matcher that compares two LocalDates and checks whether one is within [period] of the other1606 *1607 * Verifies that two LocalDates are within a certain period.1608 * For example, 09/02/1998 is within 3 days of 10/02/1998, and the matcher will have a positive result for this comparison.1609 *1610 *1611 * ```1612 * val firstDate = LocalDate.of(1998, 2, 9)1613 * val secondDate = LocalDate.of(1998, 2, 10)1614 *1615 * firstDate shouldBe within(Period.ofDays(3), secondDate) // Assertion passes1616 *1617 *1618 * val firstDate = LocalDate.of(1998, 2, 9)1619 * val secondDate = LocalDate.of(1998, 2, 25)1620 * firstDate shouldNotBe within(Period.ofDays(3), secondDate) // Assertion passes1621 * ```1622 *1623 * @see [LocalDate.shouldBeWithin]1624 * @see [LocalDate.shouldNotBeWithin]1625 */1626fun within(period: Period, date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {1627 override fun test(value: LocalDate): MatcherResult {1628 val start = date.minus(period)1629 val end = date.plus(period)1630 val passed = start == value || end == value || start.isBefore(value) && end.isAfter(value)1631 return MatcherResult(1632 passed,1633 { "$value should be within $period of $date" },1634 {1635 "$value should not be within $period of $date"1636 })1637 }1638}1639/**1640 * Asserts that this is within [temporalAmount] of [date]1641 *1642 * Verifies that this is within [temporalAmount] of [date].1643 * For example, 09/02/1998 10:00:00 is within 3 days of 10/02/1998 10:00:00, and this assertion should pass for this comparison.1644 *1645 * Opposite of [LocalDateTime.shouldNotBeWithin]1646 *1647 * ```1648 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1649 * val secondDate = LocalDateTime.of(1998, 2, 10, 10, 0, 0)1650 *1651 * firstDate.shouldBeWithin(Period.ofDays(3), secondDate) // Assertion passes1652 *1653 *1654 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1655 * val secondDate = LocalDateTime.of(1998, 2, 25, 10, 0, 0)1656 *1657 * firstDate.shouldBeWithin(Period.ofDays(3), secondDate) // Assertion fails, firstDate is not within 3 days of secondDate1658 * ```1659 */1660fun LocalDateTime.shouldBeWithin(temporalAmount: TemporalAmount, date: LocalDateTime) = this should within(temporalAmount, date)1661/**1662 * Asserts that this is NOT within [temporalAmount] of [date]1663 *1664 * Verifies that this is not within [temporalAmount] of [date].1665 * For example, 09/02/1998 10:00:00 is not within 3 days of 25/02/1998 10:00:00, and this assertion should pass for this comparison.1666 *1667 * Opposite of [LocalDateTime.shouldBeWithin]1668 *1669 * ```1670 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1671 * val secondDate = LocalDateTime.of(1998, 2, 25, 10, 0, 0)1672 *1673 * firstDate.shouldNotBeWithin(Period.ofDays(3), secondDate) // Assertion passes1674 *1675 *1676 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1677 * val secondDate = LocalDateTime.of(1998, 2, 10, 10, 0, 0)1678 *1679 * firstDate.shouldNotBeWithin(Period.ofDays(3), secondDate) // Assertion fails, firstDate is within 3 days of secondDate, and we expected not to1680 * ```1681 */1682fun LocalDateTime.shouldNotBeWithin(temporalAmount: TemporalAmount, date: LocalDateTime) = this shouldNot within(temporalAmount, date)1683/**1684 * Matcher that compares two LocalDateTimes and checks whether one is within [temporalAmount] of the other1685 *1686 * Verifies that two LocalDateTimes are within a certain period.1687 * For example, 09/02/1998 10:00:00 is within 3 days of 10/02/1998 10:00:00,1688 * and the matcher will have a positive result for this comparison.1689 *1690 *1691 * ```1692 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1693 * val secondDate = LocalDateTime.of(1998, 2, 10, 10, 0, 0)1694 *1695 * firstDate shouldBe within(Period.ofDays(3), secondDate) // Assertion passes1696 *1697 *1698 * val firstDate = LocalDateTime.of(1998, 2, 9, 10, 0, 0)1699 * val secondDate = LocalDateTime.of(1998, 2, 25, 10, 0, 0)1700 * firstDate shouldNotBe within(Period.ofDays(3), secondDate) // Assertion passes1701 * ```1702 *1703 * @see [LocalDateTime.shouldBeWithin]1704 * @see [LocalDateTime.shouldNotBeWithin]1705 */1706fun within(temporalAmount: TemporalAmount, date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {1707 override fun test(value: LocalDateTime): MatcherResult {1708 val start = date.minus(temporalAmount)1709 val end = date.plus(temporalAmount)1710 val passed = start == value || end == value || start.isBefore(value) && end.isAfter(value)1711 return MatcherResult(1712 passed,1713 { "$value should be within $temporalAmount of $date" },1714 {1715 "$value should not be within $temporalAmount of $date"1716 })1717 }1718}1719/**1720 * Asserts that this is within [temporalAmount] of [date]1721 *1722 * Verifies that this is within [temporalAmount] of [date].1723 * 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,1724 * and this assertion should pass for this comparison.1725 *1726 * Opposite of [ZonedDateTime.shouldNotBeWithin]1727 *1728 * ```1729 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1730 * val secondDate = ZonedDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1731 *1732 * firstDate.shouldBeWithin(Period.ofDays(3), secondDate) // Assertion passes1733 *1734 *1735 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1736 * val secondDate = ZonedDateTime.of(1998, 2, 25, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1737 *1738 * firstDate.shouldBeWithin(Period.ofDays(3), secondDate) // Assertion fails, firstDate is not within 3 days of secondDate1739 * ```1740 */1741fun ZonedDateTime.shouldBeWithin(temporalAmount: TemporalAmount, date: ZonedDateTime) = this should within(temporalAmount, date)1742/**1743 * Asserts that this is NOT within [temporalAmount] of [date]1744 *1745 * Verifies that this is not within [temporalAmount] of [date].1746 * For example, 09/02/1998 10:00:00 -03:00 America/Sao_Paulo is not within 3 days of 25/02/1998 10:00:00 -03:00 America/Sao_Paulo,1747 * and this assertion should pass for this comparison.1748 *1749 * Opposite of [ZonedDateTime.shouldBeWithin]1750 *1751 * ```1752 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1753 * val secondDate = ZonedDateTime.of(1998, 2, 25, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1754 *1755 * firstDate.shouldNotBeWithin(Period.ofDays(3), secondDate) // Assertion passes1756 *1757 *1758 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1759 * val secondDate = ZonedDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1760 *1761 * firstDate.shouldNotBeWithin(Period.ofDays(3), secondDate) // Assertion fails, firstDate is within 3 days of secondDate, and we expected not to1762 * ```1763 */1764fun ZonedDateTime.shouldNotBeWithin(temporalAmount: TemporalAmount, date: ZonedDateTime) = this shouldNot within(temporalAmount, date)1765/**1766 * Matcher that compares two ZonedDateTimes and checks whether one is within [temporalAmount] of the other1767 *1768 * Verifies that two ZonedDateTimes are within a certain period.1769 * 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,1770 * and the matcher will have a positive result for this comparison.1771 *1772 *1773 * ```1774 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1775 * val secondDate = ZonedDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1776 *1777 * firstDate shouldBe within(Period.ofDays(3), secondDate) // Assertion passes1778 *1779 *1780 * val firstDate = ZonedDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1781 * val secondDate = ZonedDateTime.of(1998, 2, 25, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo))1782 * firstDate shouldNotBe within(Period.ofDays(3), secondDate) // Assertion passes1783 * ```1784 *1785 * @see [ZonedDateTime.shouldBeWithin]1786 * @see [ZonedDateTime.shouldNotBeWithin]1787 */1788fun within(temporalAmount: TemporalAmount, date: ZonedDateTime): Matcher<ZonedDateTime> = object : Matcher<ZonedDateTime> {1789 override fun test(value: ZonedDateTime): MatcherResult {1790 val start = date.minus(temporalAmount)1791 val end = date.plus(temporalAmount)1792 val passed = start == value || end == value || start.isBefore(value) && end.isAfter(value)1793 return MatcherResult(1794 passed,1795 { "$value should be within $temporalAmount of $date" },1796 {1797 "$value should not be within $temporalAmount of $date"1798 })1799 }1800}1801/**1802 * Asserts that this is within [temporalAmount] of [date]1803 *1804 * Verifies that this is within [temporalAmount] of [date].1805 * For example, 09/02/1998 10:00:00 -03:00 is within 3 days of 10/02/1998 10:00:00 -03:00,1806 * and this assertion should pass for this comparison.1807 *1808 * Opposite of [OffsetDateTime.shouldNotBeWithin]1809 *1810 * ```1811 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3)1812 * val secondDate = OffsetDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1813 *1814 * firstDate.shouldBeWithin(Period.ofDays(3), secondDate) // Assertion passes1815 *1816 *1817 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1818 * val secondDate = OffsetDateTime.of(1998, 2, 25, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1819 *1820 * firstDate.shouldBeWithin(Period.ofDays(3), secondDate) // Assertion fails, firstDate is not within 3 days of secondDate1821 * ```1822 */1823fun OffsetDateTime.shouldBeWithin(temporalAmount: TemporalAmount, date: OffsetDateTime) = this should within(temporalAmount, date)1824/**1825 * Asserts that this is NOT within [temporalAmount] of [date]1826 *1827 * Verifies that this is not within [temporalAmount] of [date].1828 * For example, 09/02/1998 10:00:00 -03:00 is not within 3 days of 25/02/1998 10:00:00 -03:00,1829 * and this assertion should pass for this comparison.1830 *1831 * Opposite of [OffsetDateTime.shouldBeWithin]1832 *1833 * ```1834 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1835 * val secondDate = OffsetDateTime.of(1998, 2, 25, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1836 *1837 * firstDate.shouldNotBeWithin(Period.ofDays(3), secondDate) // Assertion passes1838 *1839 *1840 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1841 * val secondDate = OffsetDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1842 *1843 * firstDate.shouldNotBeWithin(Period.ofDays(3), secondDate) // Assertion fails, firstDate is within 3 days of secondDate, and we expected not to1844 * ```1845 */1846fun OffsetDateTime.shouldNotBeWithin(temporalAmount: TemporalAmount, date: OffsetDateTime) = this shouldNot within(temporalAmount, date)1847/**1848 * Matcher that compares two OffsetDateTimes and checks whether one is within [temporalAmount] of the other1849 *1850 * Verifies that two OffsetDateTimes are within a certain period.1851 * For example, 09/02/1998 10:00:00 -03:00 is within 3 days of 10/02/1998 10:00:00 -03:00,1852 * and the matcher will have a positive result for this comparison.1853 *1854 *1855 * ```1856 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1857 * val secondDate = OffsetDateTime.of(1998, 2, 10, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1858 *1859 * firstDate shouldBe within(Period.ofDays(3), secondDate) // Assertion passes1860 *1861 *1862 * val firstDate = OffsetDateTime.of(1998, 2, 9, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1863 * val secondDate = OffsetDateTime.of(1998, 2, 25, 10, 0, 0, 0, ZoneOffset.ofHours(-3))1864 * firstDate shouldNotBe within(Period.ofDays(3), secondDate) // Assertion passes1865 * ```1866 *1867 * @see [OffsetDateTime.shouldBeWithin]1868 * @see [OffsetDateTime.shouldNotBeWithin]1869 */1870fun within(temporalAmount: TemporalAmount, date: OffsetDateTime): Matcher<OffsetDateTime> = object : Matcher<OffsetDateTime> {1871 override fun test(value: OffsetDateTime): MatcherResult {1872 val start = date.minus(temporalAmount)1873 val end = date.plus(temporalAmount)1874 val passed = start == value || end == value || start.isBefore(value) && end.isAfter(value)1875 return MatcherResult(1876 passed,1877 { "$value should be within $temporalAmount of $date" },1878 {1879 "$value should not be within $temporalAmount of $date"1880 })1881 }1882}1883/**1884 * Asserts that this is between [a] and [b]1885 *1886 * Verifies that this is after [a] and before [b], comparing year, month and day.1887 *1888 * Opposite of [LocalDate.shouldNotBeBetween]1889 *1890 * ```1891 * val date = LocalDate.of(2019, 2, 16)1892 * val firstDate = LocalDate.of(2019, 2, 15)1893 * val secondDate = LocalDate.of(2019, 2, 17)1894 *1895 * date.shouldBeBetween(firstDate, secondDate) // Assertion passes1896 *1897 *1898 * val date = LocalDate.of(2019, 2, 15)1899 * val firstDate = LocalDate.of(2019, 2, 16)1900 * val secondDate = LocalDate.of(2019, 2, 17)1901 *1902 * date.shouldBeBetween(firstDate, secondDate) // Assertion fails, date is NOT between firstDate and secondDate1903 * ```1904 *1905 * @see LocalDate.shouldNotBeBetween1906 */1907fun LocalDate.shouldBeBetween(a: LocalDate, b: LocalDate) = this shouldBe between(a, b)1908/**1909 * Asserts that this is NOT between [a] and [b]1910 *1911 * Verifies that this is not after [a] and before [b], comparing year, month and day.1912 *1913 * Opposite of [LocalDate.shouldBeBetween]1914 *1915 * ```1916 * val date = LocalDate.of(2019, 2, 15)1917 * val firstDate = LocalDate.of(2019, 2, 16)1918 * val secondDate = LocalDate.of(2019, 2, 17)1919 *1920 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion passes1921 *1922 *1923 * val date = LocalDate.of(2019, 2, 16)1924 * val firstDate = LocalDate.of(2019, 2, 15)1925 * val secondDate = LocalDate.of(2019, 2, 17)1926 *1927 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion fails, date IS between firstDate and secondDate1928 * ```1929 *1930 * @see LocalDate.shouldBeBetween1931 */1932fun LocalDate.shouldNotBeBetween(a: LocalDate, b: LocalDate) = this shouldNotBe between(a, b)1933/**1934 * Matcher that checks if LocalDate is between two other LocalDates1935 *1936 * Verifies that LocalDate is after the first LocalDate and before the second LocalDate1937 * For example, 20/03/2019 is between 19/03/2019 and 21/03/2019, and the matcher will have a positive result for this comparison1938 *1939 * ```1940 * val date = LocalDate.of(2019, 2, 16)1941 * val firstDate = LocalDate.of(2019, 2, 15)1942 * val secondDate = LocalDate.of(2019, 2, 17)1943 *1944 * date shouldBe after(firstDate, secondDate) // Assertion passes1945 *1946 *1947 * val date = LocalDate.of(2019, 2, 15)1948 * val firstDate = LocalDate.of(2019, 2, 16)1949 * val secondDate = LocalDate.of(2019, 2, 17)1950 *1951 * date shouldNotBe between(firstDate, secondDate) // Assertion passes1952 * ```1953 *1954 * @see LocalDate.shouldBeBetween1955 * @see LocalDate.shouldNotBeBetween1956 */1957fun between(a: LocalDate, b: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {1958 override fun test(value: LocalDate): MatcherResult {1959 val passed = value.isAfter(a) && value.isBefore(b)1960 return MatcherResult(1961 passed,1962 { "$value should be after $a and before $b" },1963 {1964 "$value should not be be after $a and before $b"1965 })1966 }1967}1968/**1969 * Asserts that this is between [a] and [b]1970 *1971 * Verifies that this is after [a] and before [b], comparing all fields in LocalDateTime.1972 *1973 * Opposite of [LocalDateTime.shouldNotBeBetween]1974 *1975 * ```1976 * val date = LocalDateTime.of(2019, 2, 16, 12, 0, 0)1977 * val firstDate = LocalDateTime.of(2019, 2, 15, 12, 0, 0)1978 * val secondDate = LocalDateTime.of(2019, 2, 17, 12, 0, 0)1979 *1980 * date.shouldBeBetween(firstDate, secondDate) // Assertion passes1981 *1982 *1983 * val date = LocalDateTime.of(2019, 2, 15, 12, 0, 0)1984 * val firstDate = LocalDateTime.of(2019, 2, 16, 12, 0, 0)1985 * val secondDate = LocalDateTime.of(2019, 2, 17, 12, 0, 0)1986 *1987 * date.shouldBeBetween(firstDate, secondDate) // Assertion fails, date is NOT between firstDate and secondDate1988 * ```1989 *1990 * @see LocalDateTime.shouldNotBeBetween1991 */1992fun LocalDateTime.shouldBeBetween(a: LocalDateTime, b: LocalDateTime) = this shouldBe between(a, b)1993/**1994 * Asserts that this is NOT between [a] and [b]1995 *1996 * Verifies that this is not after [a] and before [b], comparing all fields in LocalDateTime.1997 *1998 * Opposite of [LocalDateTime.shouldBeBetween]1999 *2000 * ```2001 * val date = LocalDateTime.of(2019, 2, 15, 12, 0, 0)2002 * val firstDate = LocalDateTime.of(2019, 2, 16, 12, 0, 0)2003 * val secondDate = LocalDateTime.of(2019, 2, 17, 12, 0, 0)2004 *2005 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion passes2006 *2007 *2008 * val date = LocalDateTime.of(2019, 2, 16, 12, 0, 0)2009 * val firstDate = LocalDateTime.of(2019, 2, 15, 12, 0, 0)2010 * val secondDate = LocalDateTime.of(2019, 2, 17, 12, 0, 0)2011 *2012 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion fails, date IS between firstDate and secondDate2013 * ```2014 *2015 * @see LocalDateTime.shouldBeBetween2016 */2017fun LocalDateTime.shouldNotBeBetween(a: LocalDateTime, b: LocalDateTime) = this shouldNotBe between(a, b)2018/**2019 * Matcher that checks if LocalDateTime is between two other LocalDateTimes2020 *2021 * Verifies that LocalDateTime is after the first LocalDateTime and before the second LocalDateTime2022 * For example, 20/03/2019 10:00:00 is between 19/03/2019 10:00:00 and 21/03/2019 10:00:00, and the matcher will have a positive result for this comparison2023 *2024 * ```2025 * val date = LocalDateTime.of(2019, 2, 16, 12, 0, 0)2026 * val firstDate = LocalDateTime.of(2019, 2, 15, 12, 0, 0)2027 * val secondDate = LocalDateTime.of(2019, 2, 17, 12, 0, 0)2028 *2029 * date shouldBe after(firstDate, secondDate) // Assertion passes2030 *2031 *2032 * val date = LocalDateTime.of(2019, 2, 15, 12, 0, 0)2033 * val firstDate = LocalDateTime.of(2019, 2, 16, 12, 0, 0)2034 * val secondDate = LocalDateTime.of(2019, 2, 17, 12, 0, 0)2035 *2036 * date shouldNotBe between(firstDate, secondDate) // Assertion passes2037 * ```2038 *2039 * @see LocalDateTime.shouldBeBetween2040 * @see LocalDateTime.shouldNotBeBetween2041 */2042fun between(a: LocalDateTime, b: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {2043 override fun test(value: LocalDateTime): MatcherResult {2044 val passed = value.isAfter(a) && value.isBefore(b)2045 return MatcherResult(2046 passed,2047 { "$value should be after $a and before $b" },2048 {2049 "$value should not be be after $a and before $b"2050 })2051 }2052}2053/**2054 * Asserts that this is between [a] and [b]2055 *2056 * Verifies that this is after [a] and before [b], comparing all fields in ZonedDateTime.2057 *2058 * Opposite of [ZonedDateTime.shouldNotBeBetween]2059 *2060 * ```2061 * val date = ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2062 * val firstDate = ZonedDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2063 * val secondDate = ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2064 *2065 * date.shouldBeBetween(firstDate, secondDate) // Assertion passes2066 *2067 *2068 * val date = ZonedDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2069 * val firstDate = ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2070 * val secondDate = ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2071 *2072 * date.shouldBeBetween(firstDate, secondDate) // Assertion fails, date is NOT between firstDate and secondDate2073 * ```2074 *2075 * @see ZonedDateTime.shouldNotBeBetween2076 */2077fun ZonedDateTime.shouldBeBetween(a: ZonedDateTime, b: ZonedDateTime) = this shouldBe between(a, b)2078/**2079 * Asserts that this is NOT between [a] and [b]2080 *2081 * Verifies that this is not after [a] and before [b], comparing all fields in ZonedDateTime.2082 *2083 * Opposite of [ZonedDateTime.shouldBeBetween]2084 *2085 * ```2086 * val date = ZonedDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2087 * val firstDate = ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2088 * val secondDate = ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2089 *2090 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion passes2091 *2092 *2093 * val date = ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2094 * val firstDate = ZonedDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2095 * val secondDate = ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2096 *2097 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion fails, date IS between firstDate and secondDate2098 * ```2099 *2100 * @see ZonedDateTime.shouldBeBetween2101 */2102fun ZonedDateTime.shouldNotBeBetween(a: ZonedDateTime, b: ZonedDateTime) = this shouldNotBe between(a, b)2103/**2104 * Matcher that checks if ZonedDateTime is between two other ZonedDateTimes2105 *2106 * Verifies that ZonedDateTime is after the first ZonedDateTime and before the second ZonedDateTime2107 * For example, 20/03/2019 10:00:00 -03:00 America/Sao_Paulo is between 19/03/2019 10:00:00 -03:00 America/Sao_Paulo2108 * and 21/03/2019 10:00:00 -03:00 America/Sao_Paulo, and the matcher will have a positive result for this comparison2109 *2110 * ```2111 * val date = ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2112 * val firstDate = ZonedDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2113 * val secondDate = ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2114 *2115 * date shouldBe after(firstDate, secondDate) // Assertion passes2116 *2117 *2118 * val date = ZonedDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2119 * val firstDate = ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2120 * val secondDate = ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo"))2121 *2122 * date shouldNotBe between(firstDate, secondDate) // Assertion passes2123 * ```2124 *2125 * @see ZonedDateTime.shouldBeBetween2126 * @see ZonedDateTime.shouldNotBeBetween2127 */2128fun between(a: ZonedDateTime, b: ZonedDateTime): Matcher<ZonedDateTime> = object : Matcher<ZonedDateTime> {2129 override fun test(value: ZonedDateTime): MatcherResult {2130 val passed = value.isAfter(a) && value.isBefore(b)2131 return MatcherResult(2132 passed,2133 { "$value should be after $a and before $b" },2134 {2135 "$value should not be be after $a and before $b"2136 })2137 }2138}2139/**2140 * Asserts that this is between [a] and [b]2141 *2142 * Verifies that this is after [a] and before [b], comparing all fields in ZonedDateTime.2143 *2144 * Opposite of [OffsetDateTime.shouldNotBeBetween]2145 *2146 * ```2147 * val date = OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2148 * val firstDate = OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2149 * val secondDate = OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2150 *2151 * date.shouldBeBetween(firstDate, secondDate) // Assertion passes2152 *2153 *2154 * val date = OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2155 * val firstDate = OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2156 * val secondDate = OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2157 *2158 * date.shouldBeBetween(firstDate, secondDate) // Assertion fails, date is NOT between firstDate and secondDate2159 * ```2160 *2161 * @see OffsetDateTime.shouldNotBeBetween2162 */2163fun OffsetDateTime.shouldBeBetween(a: OffsetDateTime, b: OffsetDateTime) = this shouldBe between(a, b)2164/**2165 * Asserts that this is NOT between [a] and [b]2166 *2167 * Verifies that this is not after [a] and before [b], comparing all fields in ZonedDateTime.2168 *2169 * Opposite of [OffsetDateTime.shouldBeBetween]2170 *2171 * ```2172 * val date = OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2173 * val firstDate = OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2174 * val secondDate = OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2175 *2176 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion passes2177 *2178 *2179 * val date = OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2180 * val firstDate = OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2181 * val secondDate = OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2182 *2183 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion fails, date IS between firstDate and secondDate2184 * ```2185 *2186 * @see OffsetDateTime.shouldBeBetween2187 */2188fun OffsetDateTime.shouldNotBeBetween(a: OffsetDateTime, b: OffsetDateTime) = this shouldNotBe between(a, b)2189/**2190 * Matcher that checks if OffsetDateTime is between two other OffsetDateTimes2191 *2192 * Verifies that OffsetDateTime is after the first OffsetDateTime and before the second OffsetDateTime2193 * For example, 20/03/2019 10:00:00 -03:00 is between 19/03/2019 10:00:00 -03:00 and 21/03/2019 10:00:00 -03:00,2194 * and the matcher will have a positive result for this comparison2195 *2196 * ```2197 * val date = OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2198 * val firstDate = OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2199 * val secondDate = OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2200 *2201 * date shouldBe after(firstDate, secondDate) // Assertion passes2202 *2203 *2204 * val date = OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2205 * val firstDate = OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2206 * val secondDate = OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3))2207 *2208 * date shouldNotBe between(firstDate, secondDate) // Assertion passes2209 * ```2210 *2211 * @see OffsetDateTime.shouldBeBetween2212 * @see OffsetDateTime.shouldNotBeBetween2213 */2214fun between(a: OffsetDateTime, b: OffsetDateTime): Matcher<OffsetDateTime> = object : Matcher<OffsetDateTime> {2215 override fun test(value: OffsetDateTime): MatcherResult {2216 val passed = value.isAfter(a) && value.isBefore(b)2217 return MatcherResult(2218 passed,2219 { "$value should be after $a and before $b" },2220 {2221 "$value should not be be after $a and before $b"2222 })2223 }2224}2225/**2226 * Asserts that the day of month inputted is equaled the date day2227 *2228 * ```2229 * val date = LocalDateTime.of(2019, 2, 15, 12, 0, 0, 0)2230 *2231 * date.shouldHaveDayOfMonth(15) // Assertion passes2232 * ```2233 */2234infix fun LocalDateTime.shouldHaveDayOfMonth(day: Int) = this.dayOfMonth shouldBe day2235/**2236 * Asserts that the day of year inputted is equaled the date day2237 *2238 * ```2239 * val date = LocalDateTime.of(2019, 2, 15, 12, 0, 0, 0)2240 *2241 * date.shouldHaveDayOfYear(46) // Assertion passes2242 * ```2243 */2244infix fun LocalDateTime.shouldHaveDayOfYear(day: Int) = this.dayOfYear shouldBe day2245/**2246 * Asserts that the day of year inputted is equaled the date day2247 *2248 * ```2249 * val date = LocalDateTime.of(2019, 2, 15, 12, 0, 0, 0)2250 *2251 * date.shouldHaveDayOfWeek(FRIDAY) // Assertion passes2252 * date.shouldHaveDayOfWeek(5) // Assertion passes2253 * ```2254 */2255infix fun LocalDateTime.shouldHaveDayOfWeek(day: Int) = this.dayOfWeek.value shouldBe day2256infix fun LocalDateTime.shouldHaveDayOfWeek(day: DayOfWeek) = this.dayOfWeek shouldBe day2257/**2258 * Asserts that the month inputted is equaled the date month2259 *2260 * ```2261 * val date = LocalDateTime.of(2019, 2, 15, 12, 0, 0, 0)2262 *2263 * date.shouldHaveMonth(2) // Assertion passes2264 * date.shouldHaveMonth(FEBRUARY) // Assertion passes2265 * ```2266 */2267infix fun LocalDateTime.shouldHaveMonth(month: Int) = this.month.value shouldBe month2268infix fun LocalDateTime.shouldHaveMonth(month: Month) = this.month shouldBe month2269/**2270 * Asserts that the hour inputted is equaled the date time hour2271 *2272 * ```2273 * val date = LocalDateTime.of(2019, 2, 15, 12, 10, 0, 0)2274 *2275 * date.shouldHaveHour(12) // Assertion passes2276 * ```2277 */2278infix fun LocalDateTime.shouldHaveHour(hour: Int) = this.hour shouldBe hour2279/**2280 * Asserts that the minute inputted is equaled the date time minute2281 *2282 * ```2283 * val date = LocalDateTime.of(2019, 2, 15, 12, 10, 0, 0)2284 *2285 * date.shouldHaveMinute(10) // Assertion passes2286 * ```2287 */2288infix fun LocalDateTime.shouldHaveMinute(minute: Int) = this.minute shouldBe minute2289/**2290 * Asserts that the second inputted is equaled the date time second2291 *2292 * ```2293 * val date = LocalDateTime.of(2019, 2, 15, 12, 10, 11, 0)2294 *2295 * date.shouldHaveSecond(11) // Assertion passes2296 * ```2297 */2298infix fun LocalDateTime.shouldHaveSecond(second: Int) = this.second shouldBe second2299/**2300 * Asserts that the nano inputted is equaled the date time nano2301 *2302 * ```2303 * val date = LocalDateTime.of(2019, 2, 15, 12, 10, 0, 12)2304 *2305 * date.shouldHaveNano(10) // Assertion passes2306 * ```2307 */2308infix fun LocalDateTime.shouldHaveNano(nano: Int) = this.nano shouldBe nano2309/**2310 * Asserts that this is equal to [other] using the [ChronoZonedDateTime.isEqual]2311 *2312 * Opposite of [ZonedDateTime.shouldNotHaveSameInstantAs]2313 *2314 * ```2315 * val date = ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1))2316 * val other = ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-3))2317 *2318 * date.shouldHaveSameInstantAs(other) // Assertion passes2319 *2320 *2321 * val date = ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1))2322 * val other = ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-3))2323 *2324 * date.shouldHaveSameInstantAs(other) // Assertion fails, date is NOT equal to the other date2325 * ```2326 *2327 * @see ZonedDateTime.shouldNotHaveSameInstant2328 */2329infix fun ZonedDateTime.shouldHaveSameInstantAs(other: ZonedDateTime) = this should haveSameInstantAs(other)2330/**2331 * Asserts that this is NOT equal to [other] using the [ChronoZonedDateTime.isEqual]2332 *2333 * Opposite of [ZonedDateTime.shouldHaveSameInstantAs]2334 *2335 * ```2336 * val date = ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1))2337 * val other = ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-3))2338 *2339 * date.shouldNotHaveSameInstantAs(other) // Assertion passes2340 *2341 *2342 * val date = ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1))2343 * val other = ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-3))2344 *2345 * date.shouldNotHaveSameInstantAs(other) // Assertion fails, date is equal to the other date2346 * ```2347 *2348 * @see ZonedDateTime.shouldHaveSameInstantAs2349 */2350infix fun ZonedDateTime.shouldNotHaveSameInstantAs(other: ZonedDateTime) = this shouldNot haveSameInstantAs(other)2351/**2352 * Matcher that checks if ZonedDateTime is equal to another ZonedDateTime using the2353 * [ChronoZonedDateTime.isEqual]2354 *2355 *2356 * ```2357 * val date = ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1))2358 * val other = ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-3))2359 *2360 * date.haveSameInstantAs(other) // Assertion passes2361 *2362 *2363 * val date = ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1))2364 * val other = ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-3))2365 *2366 * date.haveSameInstantAs(other) // Assertion fails, date is NOT equal to the other date2367 * ```2368 *2369 * @see ZonedDateTime.shouldHaveSameInstantAs2370 * @see ZonedDateTime.shouldNotHaveSameInstantAs2371 */2372fun haveSameInstantAs(other: ZonedDateTime) = object : Matcher<ZonedDateTime> {2373 override fun test(value: ZonedDateTime): MatcherResult =2374 MatcherResult(2375 passed = value.isEqual(other),2376 failureMessageFn = { "$value should be equal to $other" },2377 negatedFailureMessageFn = {2378 "$value should not be equal to $other"2379 })2380}...

Full Screen

Full Screen

DateMatchersTest.kt

Source:DateMatchersTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers.date2import io.kotest.assertions.shouldFail3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.StringSpec5import io.kotest.matchers.date.after6import io.kotest.matchers.date.atSameZone7import io.kotest.matchers.date.before8import io.kotest.matchers.date.haveSameDay9import io.kotest.matchers.date.haveSameHours10import io.kotest.matchers.date.haveSameInstantAs11import io.kotest.matchers.date.haveSameMinutes12import io.kotest.matchers.date.haveSameMonth13import io.kotest.matchers.date.haveSameNanos14import io.kotest.matchers.date.haveSameSeconds15import io.kotest.matchers.date.haveSameYear16import io.kotest.matchers.date.shouldBeAfter17import io.kotest.matchers.date.shouldBeBefore18import io.kotest.matchers.date.shouldBeBetween19import io.kotest.matchers.date.shouldBeToday20import io.kotest.matchers.date.shouldBeWithin21import io.kotest.matchers.date.shouldHaveDayOfMonth22import io.kotest.matchers.date.shouldHaveDayOfWeek23import io.kotest.matchers.date.shouldHaveDayOfYear24import io.kotest.matchers.date.shouldHaveHour25import io.kotest.matchers.date.shouldHaveMinute26import io.kotest.matchers.date.shouldHaveMonth27import io.kotest.matchers.date.shouldHaveNano28import io.kotest.matchers.date.shouldHaveSameDayAs29import io.kotest.matchers.date.shouldHaveSameHoursAs30import io.kotest.matchers.date.shouldHaveSameInstantAs31import io.kotest.matchers.date.shouldHaveSameMinutesAs32import io.kotest.matchers.date.shouldHaveSameMonthAs33import io.kotest.matchers.date.shouldHaveSameNanosAs34import io.kotest.matchers.date.shouldHaveSameSecondsAs35import io.kotest.matchers.date.shouldHaveSameYearAs36import io.kotest.matchers.date.shouldHaveSecond37import io.kotest.matchers.date.shouldNotBeAfter38import io.kotest.matchers.date.shouldNotBeBefore39import io.kotest.matchers.date.shouldNotBeBetween40import io.kotest.matchers.date.shouldNotBeToday41import io.kotest.matchers.date.shouldNotBeWithin42import io.kotest.matchers.date.shouldNotHaveSameDayAs43import io.kotest.matchers.date.shouldNotHaveSameHoursAs44import io.kotest.matchers.date.shouldNotHaveSameInstantAs45import io.kotest.matchers.date.shouldNotHaveSameMinutesAs46import io.kotest.matchers.date.shouldNotHaveSameMonthAs47import io.kotest.matchers.date.shouldNotHaveSameNanosAs48import io.kotest.matchers.date.shouldNotHaveSameSecondsAs49import io.kotest.matchers.date.shouldNotHaveSameYearAs50import io.kotest.matchers.date.within51import io.kotest.matchers.shouldBe52import io.kotest.matchers.should53import io.kotest.matchers.shouldNot54import io.kotest.matchers.shouldNotBe55import java.time.DayOfWeek.SATURDAY56import java.time.Duration57import java.time.LocalDate58import java.time.LocalDateTime59import java.time.LocalTime60import java.time.Month61import java.time.OffsetDateTime62import java.time.Period63import java.time.ZoneId64import java.time.ZoneOffset65import java.time.ZonedDateTime66class DateMatchersTest : StringSpec() {67 init {68 "LocalTime should have same nanos ignoring other fields" {69 LocalTime.of(1, 2, 3, 4) should haveSameNanos(LocalTime.of(5, 6, 7, 4))70 LocalTime.of(1, 2, 3, 4) shouldNot haveSameNanos(LocalTime.of(1, 2, 3, 8))71 LocalTime.of(1, 2, 3, 4).shouldHaveSameNanosAs(LocalTime.of(5, 6, 7, 4))72 LocalTime.of(1, 2, 3, 4).shouldNotHaveSameNanosAs(LocalTime.of(1, 2, 3, 8))73 }74 "LocalTime should have same seconds ignoring other fields" {75 LocalTime.of(1, 2, 3, 4) should haveSameSeconds(LocalTime.of(5, 6, 3, 4))76 LocalTime.of(1, 2, 3, 4) shouldNot haveSameSeconds(LocalTime.of(1, 2, 5, 4))77 LocalTime.of(1, 2, 3, 4).shouldHaveSameSecondsAs(LocalTime.of(5, 6, 3, 4))78 LocalTime.of(1, 2, 3, 4).shouldNotHaveSameSecondsAs(LocalTime.of(1, 2, 5, 4))79 }80 "LocalTime should have same minutes ignoring other fields" {81 LocalTime.of(1, 2, 3, 4) should haveSameMinutes(LocalTime.of(5, 2, 7, 8))82 LocalTime.of(1, 2, 3, 4) shouldNot haveSameMinutes(LocalTime.of(1, 5, 3, 4))83 LocalTime.of(1, 2, 3, 4).shouldHaveSameMinutesAs(LocalTime.of(5, 2, 7, 8))84 LocalTime.of(1, 2, 3, 4).shouldNotHaveSameMinutesAs(LocalTime.of(1, 5, 3, 4))85 }86 "LocalTime should have same hours ignoring other fields" {87 LocalTime.of(12, 1, 2, 7777) should haveSameHours(LocalTime.of(12, 59, 58, 9999))88 LocalTime.of(3, 59, 58, 9999) shouldNot haveSameHours(LocalTime.of(12, 59, 58, 9999))89 LocalTime.of(12, 1, 2, 7777).shouldHaveSameHoursAs(LocalTime.of(12, 59, 58, 9999))90 LocalTime.of(3, 59, 58, 9999).shouldNotHaveSameHoursAs(LocalTime.of(12, 59, 58, 9999))91 }92 "LocalDate should have same year ignoring other fields" {93 LocalDate.of(2014, 1, 2) should haveSameYear(LocalDate.of(2014, 5, 6))94 LocalDate.of(2014, 1, 2) shouldNot haveSameYear(LocalDate.of(2018, 5, 6))95 LocalDate.of(2014, 1, 2).shouldHaveSameYearAs(LocalDate.of(2014, 5, 6))96 LocalDate.of(2014, 1, 2).shouldNotHaveSameYearAs(LocalDate.of(2018, 5, 6))97 }98 "LocalDateTime should have same year ignoring other fields" {99 LocalDateTime.of(2014, 1, 2, 4, 3, 2) should haveSameYear(LocalDateTime.of(2014, 5, 6, 3, 2, 1))100 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNot haveSameYear(LocalDateTime.of(2018, 5, 6, 3, 2, 1))101 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldHaveSameYearAs(LocalDateTime.of(2014, 5, 6, 3, 2, 1))102 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotHaveSameYearAs(LocalDateTime.of(2018, 5, 6, 3, 2, 1))103 }104 "ZonedDateTime should have same year ignoring other fields" {105 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) should haveSameYear(LocalDateTime.of(2014, 5, 6, 3, 2, 1).atZone(ZoneId.of("Z")))106 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNot haveSameYear(LocalDateTime.of(2018, 5, 6, 3, 2, 1).atZone(ZoneId.of("Z")))107 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldHaveSameYearAs(LocalDateTime.of(2014, 5, 6, 3, 2, 1).atZone(ZoneId.of("Z")))108 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotHaveSameYearAs(LocalDateTime.of(2018, 5, 6, 3, 2, 1).atZone(ZoneId.of("Z")))109 }110 "OffsetDateTime should have same year ignoring other fields" {111 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) should haveSameYear(LocalDateTime.of(2014, 5, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))112 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNot haveSameYear(LocalDateTime.of(2018, 5, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))113 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldHaveSameYearAs(LocalDateTime.of(2014, 5, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))114 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotHaveSameYearAs(LocalDateTime.of(2018, 5, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))115 }116 "LocalDate should have same month ignoring other fields" {117 LocalDate.of(2014, 1, 2) should haveSameMonth(LocalDate.of(2016, 1, 6))118 LocalDate.of(2014, 1, 2) shouldNot haveSameMonth(LocalDate.of(2018, 4, 6))119 LocalDate.of(2014, 1, 2).shouldHaveSameMonthAs(LocalDate.of(2016, 1, 6))120 LocalDate.of(2014, 1, 2).shouldNotHaveSameMonthAs(LocalDate.of(2018, 4, 6))121 }122 "LocalDateTime should have same month ignoring other fields" {123 LocalDateTime.of(2014, 1, 2, 4, 3, 2) should haveSameMonth(LocalDateTime.of(2014, 1, 6, 3, 2, 1))124 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNot haveSameMonth(LocalDateTime.of(2018, 2, 6, 3, 2, 1))125 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldHaveSameMonthAs(LocalDateTime.of(2014, 1, 6, 3, 2, 1))126 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotHaveSameMonthAs(LocalDateTime.of(2018, 2, 6, 3, 2, 1))127 }128 "ZonedDateTime should have same month ignoring other fields" {129 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) should haveSameMonth(LocalDateTime.of(2014, 1, 6, 3, 2, 1).atZone(ZoneId.of("Z")))130 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNot haveSameMonth(LocalDateTime.of(2018, 2, 6, 3, 2, 1).atZone(ZoneId.of("Z")))131 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldHaveSameMonthAs(LocalDateTime.of(2014, 1, 6, 3, 2, 1).atZone(ZoneId.of("Z")))132 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotHaveSameMonthAs(LocalDateTime.of(2018, 2, 6, 3, 2, 1).atZone(ZoneId.of("Z")))133 }134 "OffsetDateTime should have same month ignoring other fields" {135 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) should haveSameMonth(LocalDateTime.of(2014, 1, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))136 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNot haveSameMonth(LocalDateTime.of(2018, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))137 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldHaveSameMonthAs(LocalDateTime.of(2014, 1, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))138 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotHaveSameMonthAs(LocalDateTime.of(2018, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))139 }140 "LocalDate should have same day ignoring other fields" {141 LocalDate.of(2014, 1, 2) should haveSameDay(LocalDate.of(2014, 1, 2))142 LocalDate.of(2014, 1, 2) shouldNot haveSameDay(LocalDate.of(2014, 4, 6))143 LocalDate.of(2014, 1, 2).shouldHaveSameDayAs(LocalDate.of(2014, 1, 2))144 LocalDate.of(2014, 1, 2).shouldNotHaveSameDayAs(LocalDate.of(2014, 4, 6))145 }146 "LocalDateTime should have same day ignoring other fields" {147 LocalDateTime.of(2014, 1, 2, 4, 3, 2) should haveSameDay(LocalDateTime.of(2014, 1, 2, 3, 2, 1))148 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNot haveSameDay(LocalDateTime.of(2014, 2, 6, 3, 2, 1))149 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldHaveSameDayAs(LocalDateTime.of(2014, 1, 2, 3, 2, 1))150 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotHaveSameDayAs(LocalDateTime.of(2014, 2, 6, 3, 2, 1))151 }152 "ZonedDateTime should have same day ignoring other fields" {153 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) should haveSameDay(LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")))154 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNot haveSameDay(LocalDateTime.of(2014, 2, 6, 3, 2, 1).atZone(ZoneId.of("Z")))155 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldHaveSameDayAs(LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")))156 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotHaveSameDayAs(LocalDateTime.of(2014, 2, 6, 3, 2, 1).atZone(ZoneId.of("Z")))157 }158 "OffsetDateTime should have same day ignoring other fields" {159 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) should haveSameDay(LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC))160 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNot haveSameDay(LocalDateTime.of(2014, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))161 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldHaveSameDayAs(LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC))162 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotHaveSameDayAs(LocalDateTime.of(2014, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))163 }164 "LocalTime shouldBe before" {165 LocalTime.of(1, 2, 3, 1000) shouldBe before(LocalTime.of(1, 10, 3, 1000))166 LocalTime.of(1, 2, 3, 1000) shouldNotBe before(LocalTime.of(1, 1, 3, 1000))167 LocalTime.of(1, 2, 3, 1000).shouldBeBefore(LocalTime.of(5, 2, 3, 1000))168 LocalTime.of(1, 2, 3, 1000).shouldNotBeBefore(LocalTime.of(0, 2, 3, 1000))169 }170 "LocalDate shouldBe before" {171 LocalDate.of(2014, 1, 2) shouldBe before(LocalDate.of(2014, 1, 3))172 LocalDate.of(2014, 1, 2) shouldNotBe before(LocalDate.of(2014, 1, 1))173 LocalDate.of(2014, 1, 2).shouldBeBefore(LocalDate.of(2014, 1, 3))174 LocalDate.of(2014, 1, 2).shouldNotBeBefore(LocalDate.of(2014, 1, 1))175 }176 "LocalDateTime shouldBe before" {177 LocalDateTime.of(2014, 1, 2, 4, 3, 2) shouldBe before(LocalDateTime.of(2014, 2, 2, 3, 2, 1))178 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNotBe before(LocalDateTime.of(2014, 1, 1, 3, 2, 1))179 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldBeBefore(LocalDateTime.of(2014, 2, 2, 3, 2, 1))180 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotBeBefore(LocalDateTime.of(2014, 1, 1, 3, 2, 1))181 }182 "ZonedDateTime shouldBe before" {183 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe before(LocalDateTime.of(2014, 1, 3, 3, 2, 1).atZone(ZoneId.of("Z")))184 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe before(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atZone(ZoneId.of("Z")))185 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeBefore(LocalDateTime.of(2014, 1, 3, 3, 2, 1).atZone(ZoneId.of("Z")))186 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeBefore(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atZone(ZoneId.of("Z")))187 }188 "ZonedDateTime shouldBe equal" {189 ZonedDateTime.of(2019, 12, 10, 10, 0, 0, 0, ZoneOffset.UTC) shouldBe190 ZonedDateTime.of(2019, 12, 10, 4, 0, 0, 0, ZoneId.of("America/Chicago")).atSameZone()191 shouldThrow<AssertionError> {192 ZonedDateTime.of(2019, 12, 10, 10, 0, 0, 0, ZoneOffset.UTC) shouldBe193 ZonedDateTime.of(2019, 12, 10, 4, 1, 0, 0, ZoneId.of("America/Chicago")).atSameZone()194 }.message shouldBe "expected:<2019-12-10T10:01Z> but was:<2019-12-10T10:00Z>"195 }196 "OffsetDateTime shouldBe before" {197 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) shouldBe before(LocalDateTime.of(2016, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC))198 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNotBe before(LocalDateTime.of(2012, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))199 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldBeBefore(LocalDateTime.of(2016, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC))200 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotBeBefore(LocalDateTime.of(2012, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))201 }202 "LocalTime shouldBe after" {203 LocalTime.of(1, 2, 3, 9999) shouldBe after(LocalTime.of(1, 2, 3, 1111))204 LocalTime.of(1, 2, 3, 1000) shouldNotBe after(LocalTime.of(1, 2, 10, 1000))205 LocalTime.of(1, 2, 3, 9999).shouldBeAfter(LocalTime.of(1, 2, 3, 1111))206 LocalTime.of(1, 2, 3, 1000).shouldNotBeAfter(LocalTime.of(1, 2, 10, 1000))207 }208 "LocalDate shouldBe after" {209 LocalDate.of(2014, 1, 2) shouldBe after(LocalDate.of(2013, 1, 3))210 LocalDate.of(2014, 1, 2) shouldNotBe after(LocalDate.of(2014, 1, 3))211 LocalDate.of(2014, 1, 2).shouldBeAfter(LocalDate.of(2013, 1, 3))212 LocalDate.of(2014, 1, 2).shouldNotBeAfter(LocalDate.of(2014, 1, 3))213 }214 "LocalDateTime shouldBe after" {215 LocalDateTime.of(2014, 1, 2, 4, 3, 2) shouldBe after(LocalDateTime.of(2014, 1, 1, 3, 2, 1))216 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNotBe after(LocalDateTime.of(2014, 1, 3, 3, 2, 1))217 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldBeAfter(LocalDateTime.of(2014, 1, 1, 3, 2, 1))218 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotBeAfter(LocalDateTime.of(2014, 1, 3, 3, 2, 1))219 }220 "ZonedDateTime shouldBe after" {221 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe after(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atZone(ZoneId.of("Z")))222 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe after(LocalDateTime.of(2014, 1, 3, 3, 2, 1).atZone(ZoneId.of("Z")))223 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeAfter(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atZone(ZoneId.of("Z")))224 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeAfter(LocalDateTime.of(2014, 1, 3, 3, 2, 1).atZone(ZoneId.of("Z")))225 }226 "OffsetDateTime shouldBe after" {227 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) shouldBe after(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))228 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNotBe after(LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))229 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldBeAfter(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))230 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotBeAfter(LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))231 }232 "LocalDate shouldBe within(period, date)" {233 LocalDate.of(2014, 1, 2) shouldBe within(Period.ofDays(3), LocalDate.of(2014, 1, 1))234 LocalDate.of(2014, 1, 2) shouldBe within(Period.ofDays(3), LocalDate.of(2014, 1, 5))235 LocalDate.of(2014, 1, 2) shouldNotBe within(Period.ofDays(3), LocalDate.of(2014, 1, 6))236 LocalDate.of(2014, 1, 2).shouldBeWithin(Period.ofDays(3), LocalDate.of(2014, 1, 5))237 LocalDate.of(2014, 1, 2).shouldNotBeWithin(Period.ofDays(3), LocalDate.of(2014, 1, 6))238 }239 "LocalDateTime shouldBe within(period, date)" {240 LocalDateTime.of(2014, 1, 2, 4, 3, 2) shouldBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2))241 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNotBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2))242 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2))243 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2))244 }245 "ZonedDateTime shouldBe within(period, date)" {246 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atZone(ZoneId.of("Z")))247 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 1, 4, 3, 2).atZone(ZoneId.of("Z")))248 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2).atZone(ZoneId.of("Z")))249 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2).atZone(ZoneId.of("Z")))250 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 1, 3, 2, 0).atZone(ZoneId.of("Z")))251 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atZone(ZoneId.of("Z")))252 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 1, 4, 3, 2).atZone(ZoneId.of("Z")))253 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2).atZone(ZoneId.of("Z")))254 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2).atZone(ZoneId.of("Z")))255 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 1, 3, 2, 0).atZone(ZoneId.of("Z")))256 }257 "ZonedDateTime shouldBe within(duration, date)" {258 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atZone(ZoneId.of("Z")))259 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 1, 4, 3, 2).atZone(ZoneId.of("Z")))260 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2).atZone(ZoneId.of("Z")))261 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2).atZone(ZoneId.of("Z")))262 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 1, 3, 2, 0).atZone(ZoneId.of("Z")))263 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atZone(ZoneId.of("Z")))264 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 1, 4, 3, 2).atZone(ZoneId.of("Z")))265 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2).atZone(ZoneId.of("Z")))266 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2).atZone(ZoneId.of("Z")))267 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 1, 3, 2, 0).atZone(ZoneId.of("Z")))268 }269 "OffsetDateTime shouldBe within(period, date)" {270 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) shouldBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atOffset(ZoneOffset.UTC))271 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNotBe within(Period.ofDays(1), LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))272 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atOffset(ZoneOffset.UTC))273 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))274 }275 "OffsetDateTime shouldBe within(duration, date)" {276 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) shouldBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atOffset(ZoneOffset.UTC))277 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNotBe within(Duration.ofDays(1), LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))278 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atOffset(ZoneOffset.UTC))279 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))280 }281 "LocalTime shouldBe between" {282 LocalTime.of(14, 20, 50, 1000).shouldBeBetween(LocalTime.of(14, 20, 49), LocalTime.of(14, 20, 51))283 LocalTime.of(14, 20, 50, 1000).shouldNotBeBetween(LocalTime.of(14, 20, 51), LocalTime.of(14, 20, 52))284 }285 "LocalDate shouldBe between" {286 LocalDate.of(2019, 2, 16).shouldBeBetween(LocalDate.of(2019, 2, 15), LocalDate.of(2019, 2, 17))287 LocalDate.of(2019, 2, 16).shouldNotBeBetween(LocalDate.of(2019, 2, 17), LocalDate.of(2019, 2, 18))288 }289 "LocalDateTime shouldBe between" {290 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldBeBetween(LocalDateTime.of(2019, 2, 15, 12, 0, 0), LocalDateTime.of(2019, 2, 17, 12, 0, 0))291 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldBeBetween(LocalDateTime.of(2019, 2, 16, 10, 0, 0), LocalDateTime.of(2019, 2, 16, 14, 0, 0))292 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldNotBeBetween(LocalDateTime.of(2019, 2, 17, 12, 0, 0), LocalDateTime.of(2019, 2, 18, 12, 0, 0))293 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldNotBeBetween(LocalDateTime.of(2019, 2, 16, 18, 0, 0), LocalDateTime.of(2019, 2, 16, 20, 0, 0))294 }295 "ZonedDateTime shouldBe between" {296 ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")).shouldBeBetween(ZonedDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")), ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")))297 ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")).shouldNotBeBetween(ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")), ZonedDateTime.of(2019, 2, 18, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")))298 }299 "OffsetDateTime shouldBe between" {300 OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3)).shouldBeBetween(OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3)), OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3)))301 OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3)).shouldNotBeBetween(OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3)), OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3)))302 }303 "LocalDate.shouldBeToday() should match today" {304 LocalDate.now().shouldBeToday()305 }306 "LocalDateTime.shouldBeToday() should match today" {307 LocalDateTime.now().shouldBeToday()308 }309 "LocalDate.shouldBeToday() should not match the past" {310 shouldFail {311 LocalDate.of(2002, Month.APRIL, 1).shouldBeToday()312 }313 }314 "LocalDateTime.shouldBeToday() should not match the past" {315 shouldFail {316 LocalDateTime.of(2002, Month.APRIL, 1, 5, 2).shouldBeToday()317 }318 shouldFail {319 LocalDateTime.now().minusDays(1).shouldBeToday()320 }321 }322 "LocalDateTime.shouldNotBeToday()" {323 LocalDateTime.of(2002, Month.APRIL, 1, 5, 2).shouldNotBeToday()324 shouldFail {325 LocalDateTime.now().shouldNotBeToday()326 }327 }328 "LocalDate.shouldNotBeToday()" {329 LocalDate.of(2002, Month.APRIL, 2).shouldNotBeToday()330 shouldFail {331 LocalDateTime.now().shouldNotBeToday()332 }333 }334 "LocalDateTime should have day of month (day)" {335 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfMonth 16336 }337 "LocalDateTime should have day of week" {338 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfWeek SATURDAY339 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfWeek 6340 }341 "LocalDateTime should have day of year" {342 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfYear 47343 }344 "LocalDateTime should have month" {345 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveMonth 2346 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveMonth Month.FEBRUARY347 }348 "LocalDateTime should have hour" {349 LocalDateTime.of(2019, 2, 16, 12, 10, 0, 0) shouldHaveHour 12350 }351 "LocalDateTime should have minute" {352 LocalDateTime.of(2019, 2, 16, 12, 10, 0, 0) shouldHaveMinute 10353 }354 "LocalDateTime should have second" {355 LocalDateTime.of(2019, 2, 16, 12, 10, 13, 0) shouldHaveSecond 13356 }357 "LocalDateTime should have nano" {358 LocalDateTime.of(2019, 2, 16, 12, 10, 0, 14) shouldHaveNano 14359 }360 "ZonedDateTime should be have same instant of the given ZonedDateTime irrespective of their timezone" {361 ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1)) should haveSameInstantAs(ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-3)))362 ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1)) shouldHaveSameInstantAs ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-3))363 ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1)) shouldNot haveSameInstantAs(ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-2)))364 ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1)) shouldNotHaveSameInstantAs ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-2))365 }366 }367}...

Full Screen

Full Screen

DbUtils.kt

Source:DbUtils.kt Github

copy

Full Screen

1package no.nav.amt.tiltak.test.database2import io.kotest.matchers.date.shouldBeWithin3import io.kotest.matchers.shouldNotBe4import java.time.Duration5import java.time.LocalDate6import java.time.LocalDateTime7import java.time.ZonedDateTime8object DbUtils {9 /**10 * A helping function as SQL Timestamp and LocalDateTime does not have the same precision11 */12 fun LocalDateTime.isEqualTo(other: LocalDateTime?): Boolean {13 if (other == null) {14 return false15 }16 return this.year == other.year17 && this.month == other.month18 && this.dayOfMonth == other.dayOfMonth19 && this.hour == other.hour20 && this.minute == other.minute21 && this.second == other.second22 }23 /**24 * Should be used to check equality, 1 second skew is allowed to work around different precision on milliseconds25 */26 infix fun ZonedDateTime.shouldBeEqualTo(expected: ZonedDateTime?) {27 expected shouldNotBe null28 expected!!.shouldBeWithin(Duration.ofSeconds(1), this)29 }30 infix fun ZonedDateTime.shouldBeCloseTo(expected: ZonedDateTime?) {31 expected shouldNotBe null32 expected!!.shouldBeWithin(Duration.ofSeconds(10), this)33 }34 fun LocalDate.isEqualTo(other: LocalDate?): Boolean {35 if (other == null) {36 return false37 }38 return this.year == other.year39 && this.month == other.month40 && this.dayOfMonth == other.dayOfMonth41 }42}...

Full Screen

Full Screen

LocalDateTime.shouldBeWithin

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.date.shouldBeWithin2import io.kotest.matchers.date.shouldBeWithin3import java.time.LocalDateTime4import java.time.LocalDateTime5import java.time.temporal.ChronoUnit6import java.time.temporal.ChronoUnit7import kotlin.test.Test8import kotlin.test.Test9class LocalDateTimeMatchersTest {10class LocalDateTimeMatchersTest {11fun testLocalDateTimeShouldBeWithin() {12fun testLocalDateTimeShouldBeWithin() {13val date = LocalDateTime.now()14val date = LocalDateTime.now()15date shouldBeWithin 1L..ChronoUnit.SECONDS of LocalDateTime.now()16date shouldBeWithin 1L..ChronoUnit.SECONDS of LocalDateTime.now()17}18}19}20import io.kotest.matchers.date.shouldBeWithin21import io.kotest.matchers.date.shouldBeWithin22import java.time.LocalDateTime23import java.time.LocalDateTime24import java.time.temporal.ChronoUnit25import java.time.temporal.ChronoUnit26import kotlin.test.Test27import kotlin.test.Test28class LocalDateTimeMatchersTest {29class LocalDateTimeMatchersTest {30fun testLocalDateTimeShouldBeWithin() {31fun testLocalDateTimeShouldBeWithin() {32val date = LocalDateTime.now()33val date = LocalDateTime.now()34date shouldBeWithin 1L..ChronoUnit.SECONDS of LocalDateTime.now()35date shouldBeWithin 1L..ChronoUnit.SECONDS of LocalDateTime.now()36}37}38}39import io.kotest.matchers.date.shouldBeWithin40import io.kotest.matchers.date.shouldBeWithin41import java.time.LocalDateTime42import java.time.LocalDateTime43import java.time.temporal.ChronoUnit44import java.time.temporal.ChronoUnit45import kotlin.test.Test46import kotlin.test.Test47class LocalDateTimeMatchersTest {48class LocalDateTimeMatchersTest {49fun testLocalDateTimeShouldBeWithin() {50fun testLocalDateTimeShouldBeWithin() {51val date = LocalDateTime.now()52val date = LocalDateTime.now()53date shouldBeWithin 1L..ChronoUnit.SECONDS of LocalDateTime.now()54date shouldBeWithin 1L..ChronoUnit.SECONDS of LocalDateTime.now()55}56}57}58import io.kotest.matchers.date.shouldBeWithin

Full Screen

Full Screen

LocalDateTime.shouldBeWithin

Using AI Code Generation

copy

Full Screen

1val time1 = LocalDateTime.of(2020, 1, 1, 12, 0)2val time2 = LocalDateTime.of(2020, 1, 1, 12, 1)3time1.shouldBeWithin(1, ChronoUnit.MINUTES, time2)4val time1 = LocalDateTime.of(2020, 1, 1, 12, 0)5val time2 = LocalDateTime.of(2020, 1, 1, 12, 2)6time1.shouldBeWithin(1, ChronoUnit.MINUTES, time2)7val time1 = LocalDateTime.of(2020, 1, 1, 12, 0)8val time2 = LocalDateTime.of(2020, 1, 1, 12, 3)9time1.shouldBeWithin(1, ChronoUnit.MINUTES, time2)10val time1 = LocalDateTime.of(2020, 1, 1, 12, 0)11val time2 = LocalDateTime.of(2020, 1, 1, 12, 4)12time1.shouldBeWithin(1, ChronoUnit.MINUTES, time2)13val time1 = LocalDateTime.of(2020, 1, 1, 12, 0)14val time2 = LocalDateTime.of(2020, 1, 1, 12, 5)15time1.shouldBeWithin(1, ChronoUnit.MINUTES, time2)16val time1 = LocalDateTime.of(2020, 1, 1, 12, 0)17val time2 = LocalDateTime.of(2020, 1, 1, 12, 6)18time1.shouldBeWithin(1, ChronoUnit.MINUTES, time2)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful