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

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

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

datetime.kt

Source:datetime.kt Github

copy

Full Screen

1package io.kotest.matchers.kotlinx.datetime2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNot7import io.kotest.matchers.shouldNotBe8import kotlinx.datetime.DayOfWeek9import kotlinx.datetime.LocalDate10import kotlinx.datetime.LocalDateTime11import kotlinx.datetime.Month12import kotlinx.datetime.isoDayNumber13import kotlinx.datetime.number14/**15 * Asserts that this year is the same as [date]'s year16 *17 * Verifies that this year is the same as [date]'s year, ignoring any other fields.18 * For example, 09/02/1998 has the same year as 10/03/1998, and this assertion should pass for this comparison19 *20 * Opposite of [LocalDate.shouldNotHaveSameYearAs]21 *22 * ```23 *     val firstDate = LocalDate(1998, 2, 9)24 *     val secondDate = LocalDate(1998, 3, 10)25 *26 *     firstDate shouldHaveSameYearAs secondDate   //  Assertion passes27 *28 *29 *     val firstDate = LocalDate(2018, 2, 9)30 *     val secondDate = LocalDate(1998, 2, 9)31 *32 *     firstDate shouldHaveSameYearAs secondDate   //  Assertion fails, 2018 != 199833 ```34 */35infix fun LocalDate.shouldHaveSameYearAs(date: LocalDate) = this should haveSameYear(date)36/**37 * Asserts that this year is NOT the same as [date]'s year38 *39 * Verifies that this year isn't the same as [date]'s year, ignoring any other fields.40 * For example, 09/02/1998 doesn't have the same year as 09/02/2018, and this assertion should pass for this comparison41 *42 * Opposite of [LocalDate.shouldHaveSameYearAs]43 *44 * ```45 *    val firstDate = LocalDate(2018, 2, 9)46 *    val secondDate = LocalDate(1998, 2, 9)47 *48 *    firstDate shouldNotHaveSameYearAs secondDate    //  Assertion passes49 *50 *51 *    val firstDate = LocalDate(1998, 2, 9)52 *    val secondDate = LocalDate(1998, 3, 10)53 *54 *    firstDate shouldNotHaveSameYearAs  secondDate   //  Assertion fails, 1998 == 1998, and we expected a difference55 * ```56 */57infix fun LocalDate.shouldNotHaveSameYearAs(date: LocalDate) = this shouldNot haveSameYear(date)58/**59 * Matcher that compares years of LocalDates60 *61 * Verifies that two dates have exactly the same year, ignoring any other fields.62 * For example, 09/02/1998 has the same year as 10/03/1998, and the matcher will have a positive result for this comparison63 *64 * ```65 *    val firstDate = LocalDate(1998, 2, 9)66 *    val secondDate = LocalDate(1998, 3, 10)67 *68 *    firstDate should haveSameYear(secondDate)   //  Assertion passes69 *70 *71 *    val firstDate = LocalDate(1998, 2, 9)72 *    val secondDate = LocalDate(2018, 2, 9)73 *74 *    firstDate shouldNot haveSameYear(secondDate)    //  Assertion passes75 * ```76 *77 * @see [LocalDate.shouldHaveSameYearAs]78 * @see [LocalDate.shouldNotHaveSameYearAs]79 */80fun haveSameYear(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {81  override fun test(value: LocalDate): MatcherResult =82      MatcherResult(value.year == date.year, "$value should have year ${date.year}", "$value should not have year ${date.year}")83}84/**85 * Asserts that this year is the same as [date]'s year86 *87 * Verifies that this year is the same as [date]'s year, ignoring any other fields.88 * 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 comparison89 *90 * Opposite of [LocalDateTime.shouldNotHaveSameYearAs]91 *92 * ```93 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)94 *    val secondDate = LocalDateTime(1998, 3, 10, 11, 30, 30)95 *96 *    firstDate shouldHaveSameYearAs secondDate   //  Assertion passes97 *98 *99 *    val firstDate = LocalDateTime(2018, 2, 9, 10, 0, 0)100 *    val secondDate = LocalDateTime(1998, 2, 9, 10, 0, 0)101 *102 *    firstDate shouldHaveSameYearAs secondDate   //  Assertion fails, 2018 != 1998103 * ```104 */105infix fun LocalDateTime.shouldHaveSameYearAs(date: LocalDateTime) = this should haveSameYear(date)106/**107 * Asserts that this year is NOT the same as [date]'s year108 *109 * Verifies that this year isn't the same as [date]'s year, ignoring any other fields.110 * 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 comparison111 *112 * Opposite of [LocalDateTime.shouldHaveSameYearAs]113 *114 * ```115 *    val firstDate = LocalDateTime(2018, 2, 9, 10, 0, 0)116 *    val secondDate = LocalDateTime(1998, 3, 10, 11, 30, 30)117 *118 *    firstDate shouldNotHaveSameYearAs secondDate    //  Assertion passes119 *120 *121 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)122 *    val secondDate = LocalDateTime(1998, 3, 10, 1, 30, 30)123 *124 *    firstDate shouldNotHaveSameYearAs  secondDate   //  Assertion fails, 1998 == 1998, and we expected a difference125 * ```126 */127infix fun LocalDateTime.shouldNotHaveSameYearAs(date: LocalDateTime) = this shouldNot haveSameYear(date)128/**129 * Matcher that compares years of LocalDateTimes130 *131 * Verifies that two DateTimes have exactly the same year, ignoring any other fields.132 * 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 comparison133 *134 * ```135 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)136 *    val secondDate = LocalDateTime(1998, 3, 10, 11, 30, 30)137 *138 *    firstDate should haveSameYear(secondDate)   //  Assertion passes139 *140 *141 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)142 *    val secondDate = LocalDateTime(2018, 2, 9, 10, 0, 0)143 *144 *    firstDate shouldNot haveSameYear(secondDate)    //  Assertion passes145 * ```146 *147 * @see [LocalDateTime.shouldHaveSameYearAs]148 * @see [LocalDateTime.shouldNotHaveSameYearAs]149 */150fun haveSameYear(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {151  override fun test(value: LocalDateTime): MatcherResult =152      MatcherResult(value.year == date.year, "$value should have year ${date.year}", "$value should not have year ${date.year}")153}154/**155 * Asserts that this month is the same as [date]'s month156 *157 * Verifies that month year is the same as [date]'s month, ignoring any other fields.158 * For example, 09/02/1998 has the same month as 10/02/2018, and this assertion should pass for this comparison159 *160 * Opposite of [LocalDate.shouldNotHaveSameMonthAs]161 *162 * ```163 *    val firstDate = LocalDate(1998, 2, 9)164 *    val secondDate = LocalDate(1998, 3, 10)165 *166 *    firstDate should haveSameYear(secondDate)   //  Assertion passes167 *168 *169 *    val firstDate = LocalDate(1998, 2, 9)170 *    val secondDate = LocalDate(2018, 2, 9)171 *172 *    firstDate shouldNot haveSameYear(secondDate)    //  Assertion passes173 * ```174 */175infix fun LocalDate.shouldHaveSameMonthAs(date: LocalDate) = this should haveSameMonth(date)176/**177 * Asserts that this month is NOT the same as [date]'s month178 *179 * Verifies that this month isn't the same as [date]'s month, ignoring any other fields.180 * For example, 09/02/1998 doesn't have the same month as 09/03/1998, and this assertion should pass for this comparison181 *182 * Opposite of [LocalDate.shouldHaveSameMonthAs]183 *184 * ```185 *    val firstDate = LocalDate(1998, 2, 9)186 *    val secondDate = LocalDate(2018, 2, 10)187 *188 *    firstDate shouldHaveSameMonthAs secondDate   //  Assertion passes189 *190 *191 *    val firstDate = LocalDate(1998, 2, 9)192 *    val secondDate = LocalDate(1998, 3, 9)193 *194 *    firstDate shouldHaveSameMonthAs secondDate   //  Assertion fails, 2 != 3195 * ```196 */197infix fun LocalDate.shouldNotHaveSameMonthAs(date: LocalDate) = this shouldNot haveSameMonth(date)198/**199 * Matcher that compares months of LocalDates200 *201 * Verifies that two dates have exactly the same month, ignoring any other fields.202 * For example, 09/02/1998 has the same month as 10/02/2018, and the matcher will have a positive result for this comparison203 *204 * ```205 *    val firstDate = LocalDate(1998, 2, 9)206 *    val secondDate = LocalDate(1998, 3, 9)207 *208 *    firstDate shouldNotHaveSameMonthAs secondDate    //  Assertion passes209 *210 *211 *    val firstDate = LocalDate(1998, 2, 9)212 *    val secondDate = LocalDate(2018, 2, 10)213 *214 *    firstDate shouldNotHaveSameMonthAs  secondDate   //  Assertion fails, 2 == 2, and we expected a difference215 * ```216 *217 * @see [LocalDate.shouldHaveSameMonthAs]218 * @see [LocalDate.shouldNotHaveSameMonthAs]219 */220fun haveSameMonth(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {221  override fun test(value: LocalDate): MatcherResult =222      MatcherResult(value.month == date.month, "$value should have month ${date.month}", "$value should not have month ${date.month}")223}224/**225 * Asserts that this month is the same as [date]'s month226 *227 * Verifies that this month is the same as [date]'s month, ignoring any other fields.228 * 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 comparison229 *230 * Opposite of [LocalDateTime.shouldNotHaveSameMonthAs]231 *232 * ```233 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)234 *    val secondDate = LocalDateTime(2018, 2, 10, 10, 0, 0)235 *236 *    firstDate should haveSameMonth(secondDate)   //  Assertion passes237 *238 *239 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)240 *    val secondDate = LocalDateTime(1998, 3, 9, 10, 0, 0)241 *242 *    firstDate shouldNot haveSameMonth(secondDate)    //  Assertion passes243 * ```244 */245infix fun LocalDateTime.shouldHaveSameMonthAs(date: LocalDateTime) = this should haveSameMonth(date)246/**247 * Asserts that this month is NOT the same as [date]'s month248 *249 * Verifies that this month isn't the same as [date]'s month, ignoring any other fields.250 * 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 comparison251 *252 * Opposite of [LocalDateTime.shouldHaveSameMonthAs]253 *254 * ```255 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)256 *    val secondDate = LocalDateTime(2018, 2, 10, 11, 30, 30)257 *258 *    firstDate shouldHaveSameMonthAs secondDate   //  Assertion passes259 *260 *261 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)262 *    val secondDate = LocalDateTime(1998, 3, 9, 10, 0, 0)263 *264 *    firstDate shouldHaveSameMonthAs secondDate   //  Assertion fails, 2 != 3265 * ```266 */267infix fun LocalDateTime.shouldNotHaveSameMonthAs(date: LocalDateTime) = this shouldNot haveSameMonth(date)268/**269 * Matcher that compares months of LocalDateTimes270 *271 * Verifies that two DateTimes have exactly the same month, ignoring any other fields.272 * 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 comparison273 *274 * ```275 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)276 *    val secondDate = LocalDateTime(1998, 3, 10, 11, 30, 30)277 *278 *    firstDate shouldNotHaveSameMonthAs secondDate    //  Assertion passes279 *280 *281 *    val firstDate = LocalDateTime(2018, 2, 9, 10, 0, 0)282 *    val secondDate = LocalDateTime(1998, 2, 10, 1, 30, 30)283 *284 *    firstDate shouldNotHaveSameMonthAs  secondDate   //  Assertion fails, 2 == 2, and we expected a difference285 * ```286 *287 * @see [LocalDateTime.shouldHaveSameMonthAs]288 * @see [LocalDateTime.shouldNotHaveSameMonthAs]289 */290fun haveSameMonth(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {291  override fun test(value: LocalDateTime): MatcherResult =292      MatcherResult(value.month == date.month, "$value should have month ${date.month}", "$value should not have month ${date.month}")293}294/**295 * Asserts that this day is the same as [date]'s day296 *297 * Verifies that this day is the same as [date]'s day, ignoring any other fields.298 * For example, 09/02/1998 has the same day as 09/03/2018, and this assertion should pass for this comparison299 *300 * Opposite of [LocalDate.shouldNotHaveSameDayAs]301 *302 * ```303 *    val firstDate = LocalDate(1998, 2, 9)304 *    val secondDate = LocalDate(2018, 3, 9)305 *306 *    firstDate shouldHaveSameDayAs secondDate   //  Assertion passes307 *308 *309 *    val firstDate = LocalDate(1998, 2, 9)310 *    val secondDate = LocalDate(1998, 2, 10)311 *312 *    firstDate shouldHaveSameDayAs secondDate   //  Assertion fails, 9 != 10313 * ```314 */315infix fun LocalDate.shouldHaveSameDayAs(date: LocalDate) = this should haveSameDay(date)316/**317 * Asserts that this day is NOT the same as [date]'s day318 *319 * Verifies that this day isn't the same as [date]'s day, ignoring any other fields.320 * For example, 09/02/1998 doesn't have the same day as 10/02/1998, and this assertion should pass for this comparison321 *322 * Opposite of [LocalDate.shouldHaveSameDayAs]323 *324 * ```325 *    val firstDate = LocalDate(1998, 2, 9)326 *    val secondDate = LocalDate(1998, 2, 10)327 *328 *    firstDate shouldNotHaveSameDayAs secondDate    //  Assertion passes329 *330 *331 *    val firstDate = LocalDate(1998, 2, 9)332 *    val secondDate = LocalDate(2018, 3, 9)333 *334 *    firstDate shouldNotHaveSameDayAs  secondDate   //  Assertion fails, 9 == 9, and we expected a difference335 * ```336 */337infix fun LocalDate.shouldNotHaveSameDayAs(date: LocalDate) = this shouldNot haveSameDay(date)338/**339 * Matcher that compares days of LocalDates340 *341 * Verifies that two dates have exactly the same day, ignoring any other fields.342 * For example, 09/02/1998 has the same day as 09/03/2018, and the matcher will have a positive result for this comparison343 *344 * ```345 *    val firstDate = LocalDate(1998, 2, 9)346 *    val secondDate = LocalDate(2018, 3, 9)347 *348 *    firstDate should haveSameDay(secondDate)   //  Assertion passes349 *350 *351 *    val firstDate = LocalDate(1998, 2, 9)352 *    val secondDate = LocalDate(1998, 2, 10)353 *354 *    firstDate shouldNot haveSameDay(secondDate)    //  Assertion passes355 * ```356 *357 * @see [LocalDate.shouldHaveSameDayAs]358 * @see [LocalDate.shouldNotHaveSameDayAs]359 */360fun haveSameDay(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {361  override fun test(value: LocalDate): MatcherResult =362      MatcherResult(value.dayOfMonth == date.dayOfMonth, "$value should have day ${date.dayOfMonth} but had ${value.dayOfMonth}", "$value should not have day ${date.dayOfMonth}")363}364/**365 * Asserts that this day is the same as [date]'s day366 *367 * Verifies that this day is the same as [date]'s day, ignoring any other fields.368 * 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 comparison369 *370 * Opposite of [LocalDateTime.shouldNotHaveSameDayAs]371 *372 * ```373 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)374 *    val secondDate = LocalDateTime(1998, 3, 9, 11, 30, 30)375 *376 *    firstDate shouldHaveSameDayAs secondDate   //  Assertion passes377 *378 *379 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)380 *    val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)381 *382 *    firstDate shouldHaveSameDayAs secondDate   //  Assertion fails, 9 != 10383 * ```384 */385infix fun LocalDateTime.shouldHaveSameDayAs(date: LocalDateTime) = this should haveSameDay(date)386/**387 * Asserts that this day is NOT the same as [date]'s day388 *389 * Verifies that this year isn't the same as [date]'s day, ignoring any other fields.390 * 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 comparison391 *392 * Opposite of [LocalDateTime.shouldHaveSameDayAs]393 *394 * ```395 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)396 *    val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)397 *398 *    firstDate shouldNotHaveSameDayAs secondDate    // Assertion passes399 *400 *401 *    val firstDate = LocalDateTime(2018, 2, 9, 10, 0, 0)402 *    val secondDate = LocalDateTime(1998, 3, 9, 11, 30, 30)403 *404 *    firstDate shouldNotHaveSameDayAs  secondDate   // Assertion fails, 9 == 9, and we expected a difference405 * ```406 */407infix fun LocalDateTime.shouldNotHaveSameDayAs(date: LocalDateTime) = this shouldNot haveSameDay(date)408/**409 * Matcher that compares days of LocalDateTimes410 *411 * Verifies that two DateTimes have exactly the same day, ignoring any other fields.412 * 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 comparison413 *414 * ```415 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)416 *    val secondDate = LocalDateTime(2018, 3, 9, 11, 30, 30)417 *418 *    firstDate should haveSameDay(secondDate)   // Assertion passes419 *420 *421 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)422 *    val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)423 *424 *    firstDate shouldNot haveSameDay(secondDate)    // Assertion passes425 * ```426 *427 * @see [LocalDateTime.shouldHaveSameDayAs]428 * @see [LocalDateTime.shouldNotHaveSameDayAs]429 */430fun haveSameDay(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {431  override fun test(value: LocalDateTime): MatcherResult =432      MatcherResult(value.dayOfMonth == date.dayOfMonth, "$value should have day ${date.dayOfMonth} but had ${value.dayOfMonth}", "$value should not have day ${date.dayOfMonth}")433}434/**435 * Asserts that this is before [date]436 *437 * Verifies that this is before [date], comparing year, month and day.438 * For example, 09/02/1998 is before 10/02/1998, and this assertion should pass for this comparison.439 *440 * Opposite of [LocalDate.shouldNotBeBefore]441 *442 * ```443 *    val firstDate = LocalDate(1998, 2, 9)444 *    val secondDate = LocalDate(1998, 2, 10)445 *446 *    firstDate shouldBeBefore secondDate    // Assertion passes447 *448 *449 *    val firstDate = LocalDate(1998, 2, 10)450 *    val secondDate = LocalDate(1998, 2, 9)451 *452 *    firstDate shouldBeBefore secondDate     // Assertion fails, 10/02/1998 is not before 09/02/1998 as expected.453 * ```454 *455 * @see LocalDate.shouldNotBeAfter456 */457infix fun LocalDate.shouldBeBefore(date: LocalDate) = this should before(date)458/**459 * Asserts that this is NOT before [date]460 *461 * Verifies that this is not before [date], comparing year, month and day.462 * For example, 10/02/1998 is not before 09/02/1998, and this assertion should pass for this comparison.463 *464 * Opposite of [LocalDate.shouldBeBefore]465 *466 * ```467 *    val firstDate = LocalDate(1998, 2, 10)468 *    val secondDate = LocalDate(1998, 2, 9)469 *470 *    firstDate shouldNotBeBefore secondDate    // Assertion passes471 *    val firstDate = LocalDate(1998, 2, 9)472 *    val secondDate = LocalDate(1998, 2, 10)473 *474 *    firstDate shouldNotBeBefore secondDate     // Assertion fails, 09/02/1998 is before 10/02/1998, and we expected the opposite.475 * ```476 *477 * @see LocalDate.shouldBeAfter478 */479infix fun LocalDate.shouldNotBeBefore(date: LocalDate) = this shouldNot before(date)480/**481 * Matcher that compares two LocalDates and checks whether one is before the other482 *483 * Verifies that two LocalDates occurs in a certain order, checking that one happened before the other.484 * For example, 09/02/1998 is before 10/02/1998, and the matcher will have a positive result for this comparison485 *486 * ```487 *    val firstDate = LocalDate(1998, 2, 9)488 *    val secondDate = LocalDate(1998, 2, 10)489 *490 *    firstDate shouldBe before(secondDate)     // Assertion passes491 *492 *493 *    val firstDate = LocalDate(1998, 2, 10)494 *    val secondDate = LocalDate(1998, 2, 9)495 *496 *    firstDate shouldNotBe before(secondDate)  // Assertion passes497 * ```498 *499 * @see LocalDate.shouldBeBefore500 * @see LocalDate.shouldNotBeBefore501 */502fun before(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {503  override fun test(value: LocalDate): MatcherResult =504      MatcherResult(value < date, "$value should be before $date", "$value should not be before $date")505}506/**507 * Asserts that this is before [date]508 *509 * Verifies that this is before [date], comparing every field in the LocalDateTime.510 * For example, 09/02/1998 00:00:00 is before 09/02/1998 00:00:01, and this assertion should pass for this comparison.511 *512 * Opposite of [LocalDateTime.shouldNotBeBefore]513 *514 * ```515 *    val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 0)516 *    val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 1)517 *518 *    firstDate shouldBeBefore secondDate    // Assertion passes519 *520 *521 *    val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 1)522 *    val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 0)523 *524 *    firstDate shouldBeBefore secondDate     // Assertion fails, firstDate is one second after secondDate525 * ```526 *527 * @see LocalDateTime.shouldNotBeAfter528 */529infix fun LocalDateTime.shouldBeBefore(date: LocalDateTime) = this should before(date)530/**531 * Asserts that this is NOT before [date]532 *533 * Verifies that this is not before [date], comparing every field in the LocalDateTime.534 * 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.535 *536 * Opposite of [LocalDateTime.shouldBeBefore]537 *538 * ```539 *    val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 1)540 *    val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 0)541 *542 *    firstDate shouldNotBeBefore secondDate    // Assertion passes543 *544 *545 *    val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 0)546 *    val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 1)547 *548 *    firstDate shouldNotBeBefore secondDate     // Assertion fails, firstDate is one second before secondDate and we didn't expect it549 * ```550 *551 * @see LocalDateTime.shouldBeAfter552 */553infix fun LocalDateTime.shouldNotBeBefore(date: LocalDateTime) = this shouldNot before(date)554/**555 * Matcher that compares two LocalDateTimes and checks whether one is before the other556 *557 * Verifies that two LocalDateTimes occurs in a certain order, checking that one happened before the other.558 * 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 comparison559 *560 * ```561 *    val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 0)562 *    val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 1)563 *564 *    firstDate shouldBe before(secondDate)     // Assertion passes565 *566 *567 *    val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 1)568 *    val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 0)569 *570 *    firstDate shouldNotBe before(secondDate)  // Assertion passes571 * ```572 *573 * @see LocalDateTime.shouldBeBefore574 * @see LocalDateTime.shouldNotBeBefore575 */576fun before(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {577  override fun test(value: LocalDateTime): MatcherResult =578      MatcherResult(value < date, "$value should be before $date", "$value should not be before $date")579}580/**581 * Asserts that this is after [date]582 *583 * Verifies that this is after [date], comparing year, month and day.584 * For example, 09/02/1998 is after 08/02/1998, and this assertion should pass for this comparison.585 *586 * Opposite of [LocalDate.shouldNotBeAfter]587 *588 * ```589 *    val firstDate = LocalDate(1998, 2, 9)590 *    val secondDate = LocalDate(1998, 2, 8)591 *592 *    firstDate shouldBeAfter secondDate  // Assertion passes593 *594 *595 *    val firstDate = LocalDate(1998, 2, 9)596 *    val secondDate = LocalDate(1998, 2, 10)597 *598 *    firstDate shouldBeAfter secondDate  // Assertion fails, firstDate is NOT after secondDate599 * ```600 *601 * @see LocalDate.shouldNotBeBefore602 */603infix fun LocalDate.shouldBeAfter(date: LocalDate) = this should after(date)604/**605 * Asserts that this is NOT after [date]606 *607 * Verifies that this is not after [date], comparing year, month and day.608 * For example, 09/02/1998 is not after 10/02/1998, and this assertion should pass for this comparison.609 *610 * Opposite of [LocalDate.shouldBeAfter]611 *612 * ```613 *    val firstDate = LocalDate(1998, 2, 9)614 *    val secondDate = LocalDate(1998, 2, 10)615 *616 *    firstDate shouldNotBeAfter secondDate   // Assertion passes617 *618 *619 *    val firstDate = LocalDate(1998, 2, 10)620 *    val secondDate = LocalDate(1998, 2, 9)621 *622 *    firstDate shouldNotBeAfter secondDate   // Assertion fails, first date IS after secondDate623 * ```624 *625 * @see LocalDate.shouldBeBefore626 */627infix fun LocalDate.shouldNotBeAfter(date: LocalDate) = this shouldNot after(date)628/**629 * Matcher that compares two LocalDates and checks whether one is after the other630 *631 * Verifies that two LocalDates occurs in a certain order, checking that one happened after the other.632 * For example, 10/02/1998 is after 09/02/1998, and the matcher will have a positive result for this comparison633 *634 * ```635 *    val firstDate = LocalDate(1998, 2, 9)636 *    val secondDate = LocalDate(1998, 2, 8)637 *638 *    firstDate shouldBe after(secondDate ) // Assertion passes639 *640 *641 *    val firstDate = LocalDate(1998, 2, 9)642 *    val secondDate = LocalDate(1998, 2, 10)643 *644 *    firstDate shouldNotBe after(secondDate)   // Assertion passes645 * ```646 *647 * @see LocalDate.shouldBeAfter648 * @see LocalDate.shouldNotBeAfter649 */650fun after(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {651  override fun test(value: LocalDate): MatcherResult =652      MatcherResult(value > date, "$value should be after $date", "$value should not be after $date")653}654/**655 * Asserts that this is after [date]656 *657 * Verifies that this is after [date], comparing all fields in LocalDateTime.658 * For example, 09/02/1998 10:00:00 is after 09/02/1998 09:00:00, and this assertion should pass for this comparison.659 *660 * Opposite of [LocalDateTime.shouldNotBeAfter]661 *662 * ```663 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)664 *    val secondDate = LocalDateTime(1998, 2, 8, 10, 0, 0)665 *666 *    firstDate shouldBeAfter secondDate  // Assertion passes667 *668 *669 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)670 *    val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)671 *672 *    firstDate shouldBeAfter secondDate  // Assertion fails, firstDate is NOT after secondDate673 * ```674 *675 * @see LocalDateTime.shouldNotBeBefore676 */677infix fun LocalDateTime.shouldBeAfter(date: LocalDateTime) = this should after(date)678/**679 * Asserts that this is NOT after [date]680 *681 * Verifies that this is not after [date], comparing all fields in LocalDateTime.682 * 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.683 *684 * Opposite of [LocalDateTime.shouldBeAfter]685 *686 * ```687 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)688 *    val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)689 *690 *    firstDate shouldNotBeAfter secondDate   // Assertion passes691 *692 *693 *    val firstDate = LocalDateTime(1998, 2, 10, 10, 0, 0)694 *    val secondDate = LocalDateTime(1998, 2, 9, 10, 0, 0)695 *696 *    firstDate shouldNotBeAfter secondDate   // Assertion fails, first date IS after secondDate697 * ```698 *699 * @see LocalDateTime.shouldBeBefore700 */701infix fun LocalDateTime.shouldNotBeAfter(date: LocalDateTime) = this shouldNot after(date)702/**703 * Matcher that compares two LocalDateTimes and checks whether one is after the other704 *705 * Verifies that two LocalDateTimes occurs in a certain order, checking that one happened after the other.706 * 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 comparison707 *708 * ```709 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)710 *    val secondDate = LocalDateTime(1998, 2, 8, 10, 0, 0)711 *712 *    firstDate shouldBe after(secondDate ) // Assertion passes713 *714 *715 *    val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)716 *    val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)717 *718 *    firstDate shouldNotBe after(secondDate)   // Assertion passes719 * ```720 *721 * @see LocalDateTime.shouldBeAfter722 * @see LocalDateTime.shouldNotBeAfter723 */724fun after(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {725  override fun test(value: LocalDateTime): MatcherResult =726      MatcherResult(value > date, "$value should be after $date", "$value should not be after $date")727}728/**729 * Asserts that this is between [a] and [b]730 *731 * Verifies that this is after [a] and before [b], comparing year, month and day.732 *733 * Opposite of [LocalDate.shouldNotBeBetween]734 *735 * ```736 *    val date = LocalDate(2019, 2, 16)737 *    val firstDate = LocalDate(2019, 2, 15)738 *    val secondDate = LocalDate(2019, 2, 17)739 *740 *    date.shouldBeBetween(firstDate, secondDate)  // Assertion passes741 *742 *743 *    val date = LocalDate(2019, 2, 15)744 *    val firstDate = LocalDate(2019, 2, 16)745 *    val secondDate = LocalDate(2019, 2, 17)746 *747 *    date.shouldBeBetween(firstDate, secondDate)  // Assertion fails, date is NOT between firstDate and secondDate748 * ```749 *750 * @see LocalDate.shouldNotBeBetween751 */752fun LocalDate.shouldBeBetween(a: LocalDate, b: LocalDate) = this shouldBe between(a, b)753/**754 * Asserts that this is NOT between [a] and [b]755 *756 * Verifies that this is not after [a] and before [b], comparing year, month and day.757 *758 * Opposite of [LocalDate.shouldBeBetween]759 *760 * ```761 *    val date = LocalDate(2019, 2, 15)762 *    val firstDate = LocalDate(2019, 2, 16)763 *    val secondDate = LocalDate(2019, 2, 17)764 *765 *    date.shouldNotBeBetween(firstDate, secondDate) // Assertion passes766 *767 *768 *    val date = LocalDate(2019, 2, 16)769 *    val firstDate = LocalDate(2019, 2, 15)770 *    val secondDate = LocalDate(2019, 2, 17)771 *772 *    date.shouldNotBeBetween(firstDate, secondDate)  // Assertion fails, date IS between firstDate and secondDate773 * ```774 *775 * @see LocalDate.shouldBeBetween776 */777fun LocalDate.shouldNotBeBetween(a: LocalDate, b: LocalDate) = this shouldNotBe between(a, b)778/**779 * Matcher that checks if LocalDate is between two other LocalDates780 *781 * Verifies that LocalDate is after the first LocalDate and before the second LocalDate782 * For example, 20/03/2019 is between 19/03/2019 and 21/03/2019, and the matcher will have a positive result for this comparison783 *784 * ```785 *    val date = LocalDate(2019, 2, 16)786 *    val firstDate = LocalDate(2019, 2, 15)787 *    val secondDate = LocalDate(2019, 2, 17)788 *789 *    date shouldBe after(firstDate, secondDate) // Assertion passes790 *791 *792 *    val date = LocalDate(2019, 2, 15)793 *    val firstDate = LocalDate(2019, 2, 16)794 *    val secondDate = LocalDate(2019, 2, 17)795 *796 *    date shouldNotBe between(firstDate, secondDate)   // Assertion passes797 * ```798 *799 * @see LocalDate.shouldBeBetween800 * @see LocalDate.shouldNotBeBetween801 */802fun between(a: LocalDate, b: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {803  override fun test(value: LocalDate): MatcherResult {804    val passed = value > a && value < b805    return MatcherResult(passed, "$value should be after $a and before $b", "$value should not be be after $a and before $b")806  }807}808/**809 * Asserts that this is between [a] and [b]810 *811 * Verifies that this is after [a] and before [b], comparing all fields in LocalDateTime.812 *813 * Opposite of [LocalDateTime.shouldNotBeBetween]814 *815 * ```816 *    val date = LocalDateTime(2019, 2, 16, 12, 0, 0)817 *    val firstDate = LocalDateTime(2019, 2, 15, 12, 0, 0)818 *    val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)819 *820 *    date.shouldBeBetween(firstDate, secondDate)  // Assertion passes821 *822 *823 *    val date = LocalDateTime(2019, 2, 15, 12, 0, 0)824 *    val firstDate = LocalDateTime(2019, 2, 16, 12, 0, 0)825 *    val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)826 *827 *    date.shouldBeBetween(firstDate, secondDate)  // Assertion fails, date is NOT between firstDate and secondDate828 * ```829 *830 * @see LocalDateTime.shouldNotBeBetween831 */832fun LocalDateTime.shouldBeBetween(a: LocalDateTime, b: LocalDateTime) = this shouldBe between(a, b)833/**834 * Asserts that this is NOT between [a] and [b]835 *836 * Verifies that this is not after [a] and before [b], comparing all fields in LocalDateTime.837 *838 * Opposite of [LocalDateTime.shouldBeBetween]839 *840 * ```841 *    val date = LocalDateTime(2019, 2, 15, 12, 0, 0)842 *    val firstDate = LocalDateTime(2019, 2, 16, 12, 0, 0)843 *    val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)844 *845 *    date.shouldNotBeBetween(firstDate, secondDate) // Assertion passes846 *847 *848 *    val date = LocalDateTime(2019, 2, 16, 12, 0, 0)849 *    val firstDate = LocalDateTime(2019, 2, 15, 12, 0, 0)850 *    val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)851 *852 *    date.shouldNotBeBetween(firstDate, secondDate)  // Assertion fails, date IS between firstDate and secondDate853 * ```854 *855 * @see LocalDateTime.shouldBeBetween856 */857fun LocalDateTime.shouldNotBeBetween(a: LocalDateTime, b: LocalDateTime) = this shouldNotBe between(a, b)858/**859 * Matcher that checks if LocalDateTime is between two other LocalDateTimes860 *861 * Verifies that LocalDateTime is after the first LocalDateTime and before the second LocalDateTime862 * 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 comparison863 *864 * ```865 *    val date = LocalDateTime(2019, 2, 16, 12, 0, 0)866 *    val firstDate = LocalDateTime(2019, 2, 15, 12, 0, 0)867 *    val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)868 *869 *    date shouldBe after(firstDate, secondDate) // Assertion passes870 *871 *872 *    val date = LocalDateTime(2019, 2, 15, 12, 0, 0)873 *    val firstDate = LocalDateTime(2019, 2, 16, 12, 0, 0)874 *    val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)875 *876 *    date shouldNotBe between(firstDate, secondDate)   // Assertion passes877 * ```878 *879 * @see LocalDateTime.shouldBeBetween880 * @see LocalDateTime.shouldNotBeBetween881 */882fun between(a: LocalDateTime, b: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {883  override fun test(value: LocalDateTime): MatcherResult {884    val passed = value > a && value < b885    return MatcherResult(passed, "$value should be after $a and before $b", "$value should not be be after $a and before $b")886  }887}888/**889 * Asserts that the day of month inputted is equaled the date day890 *891 * ```892 *    val date = LocalDateTime(2019, 2, 15, 12, 0, 0, 0)893 *894 *    date.shouldHaveDayOfMonth(15) // Assertion passes895 * ```896 */897infix fun LocalDateTime.shouldHaveDayOfMonth(day: Int) = this.dayOfMonth shouldBe day898/**899 * Asserts that the day of year inputted is equaled the date day900 *901 * ```902 *    val date = LocalDateTime(2019, 2, 15, 12, 0, 0, 0)903 *904 *    date.shouldHaveDayOfYear(46) // Assertion passes905 * ```906 */907infix fun LocalDateTime.shouldHaveDayOfYear(day: Int) = this.dayOfYear shouldBe day908/**909 * Asserts that the day of year inputted is equaled the date day910 *911 * ```912 *    val date = LocalDateTime(2019, 2, 15, 12, 0, 0, 0)913 *914 *    date.shouldHaveDayOfWeek(FRIDAY) // Assertion passes915 *    date.shouldHaveDayOfWeek(5) // Assertion passes916 * ```917 */918infix fun LocalDateTime.shouldHaveDayOfWeek(day: Int) = this.dayOfWeek.isoDayNumber shouldBe day919infix fun LocalDateTime.shouldHaveDayOfWeek(day: DayOfWeek) = this.dayOfWeek shouldBe day920/**921 * Asserts that the month inputted is equaled the date month922 *923 * ```924 *    val date = LocalDateTime(2019, 2, 15, 12, 0, 0, 0)925 *926 *    date.shouldHaveMonth(2) // Assertion passes927 *    date.shouldHaveMonth(FEBRUARY) // Assertion passes928 * ```929 */930infix fun LocalDateTime.shouldHaveMonth(month: Int) = this.month.number shouldBe month931infix fun LocalDateTime.shouldHaveMonth(month: Month) = this.month shouldBe month932/**933 * Asserts that the hour inputted is equaled the date time hour934 *935 * ```936 *    val date = LocalDateTime(2019, 2, 15, 12, 10, 0, 0)937 *938 *    date.shouldHaveHour(12) // Assertion passes939 * ```940 */941infix fun LocalDateTime.shouldHaveHour(hour: Int) = this.hour shouldBe hour942/**943 * Asserts that the minute inputted is equaled the date time minute944 *945 * ```946 *    val date = LocalDateTime(2019, 2, 15, 12, 10, 0, 0)947 *948 *    date.shouldHaveMinute(10) // Assertion passes949 * ```950 */951infix fun LocalDateTime.shouldHaveMinute(minute: Int) = this.minute shouldBe minute952/**953 * Asserts that the second inputted is equaled the date time second954 *955 * ```956 *    val date = LocalDateTime(2019, 2, 15, 12, 10, 11, 0)957 *958 *    date.shouldHaveSecond(11) // Assertion passes959 * ```960 */961infix fun LocalDateTime.shouldHaveSecond(second: Int) = this.second shouldBe second962/**963 * Asserts that the nano inputted is equaled the date time nano964 *965 * ```966 *    val date = LocalDateTime(2019, 2, 15, 12, 10, 0, 12)967 *968 *    date.shouldHaveNano(10) // Assertion passes969 * ```970 */971infix fun LocalDateTime.shouldHaveNano(nano: Int) = this.nanosecond shouldBe nano...

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

OrganizacionTest.kt

Source:OrganizacionTest.kt Github

copy

Full Screen

1package ar.edu.unahur.obj2.teseifest2import ar.edu.unahur.obj2.caralibro.Pop3import ar.edu.unahur.obj2.caralibro.Rock4import ar.edu.unahur.obj2.caralibro.Trap5import io.kotest.assertions.throwables.shouldThrowAny6import io.kotest.core.spec.style.DescribeSpec7import io.kotest.matchers.ints.shouldBeBetween8import io.kotest.matchers.shouldBe9import java.time.LocalDateTime10class OrganizacionTest : DescribeSpec({11    describe("Test de estadísticas") {12        val participante1 = Participante(17, "insta1", "1155555555", "Sumados", "Trueno", "Tini" )13        val participante2 = Participante(18, "insta2", "1155555555", "Trueno", "Wos", "Abel Pintos")14        val participante3 = Participante(20, "insta3", "1555555555", "Joya Nunca Taxi", "Sumados", "Wos")15        val participante4 = Participante(20, "insta4", "1555555555", "Joya Nunca Taxi", "Sumados", "Trueno")16        val foodtruck1 = FoodTruck()17        val foodtruck2 = FoodTruck()18        val bondiolaVegana = Comida(1000, "BONDIOLA VEGANA", foodtruck1, true )19        val cerveza = Bebida( 500, "CERVEZA", 400, 5.0, foodtruck1, true)20        val bebidaFuerte = Bebida(500, "BEBIDA FUERTE", 200, 40.0, foodtruck2, true)21        val milkshake = Bebida(500, "MILKSHAKE", 500, 0.0, foodtruck2, false)22        val bondiola = Comida(1000, "BONDIOLA", foodtruck2, false)23        Organizacion.foodTrucks.clear()24        Organizacion.registroIngresos.clear()25        Rock.registroVip.clear()26        Pop.registroVip.clear()27        Trap.registroVip.clear()28        Organizacion.agregarFoodTruck(foodtruck1)29        Organizacion.agregarFoodTruck(foodtruck2)30        participante1.ingresarAlFestival()31        participante2.ingresarAlFestival()32        participante3.ingresarAlFestival()33        participante1.compraEntradaFAN()34        participante2.compraEntradaREFAN()35        it("Cuantos accesos vendió"){36            Organizacion.cantidadAccesosVendidos().shouldBe(2)37        }38        it("Cuanto se vendió en total, es decir plata de accesos y plata de foodtrucks"){39            participante1.comprarAlgo(bondiola)40            participante3.comprarAlgo(bebidaFuerte)41            participante2.comprarAlgo(cerveza)42            participante2.comprarAlgo(cerveza)43            // 1000 + 500 + 500 + 500 de los foodtrucks y 1000 + 2000 de los accesos. Total = $ 550044            Organizacion.cantidadTotalVendida().shouldBe(5500)45        }46        it("Cual es el promedio de plata que gastó un participante"){47            participante1.comprarAlgo(bondiola)48            participante3.comprarAlgo(bebidaFuerte)49            participante2.comprarAlgo(cerveza)50            participante2.comprarAlgo(cerveza)51            // 1000 + 500 + 500 + 500 de los foodtrucks y 1000 + 2000 de los accesos. Total = $ 550052            // 5500 / 3 = 1833,3353            Organizacion.promedioGastadoPorParticipante().shouldBe(1833)54            participante1.comprarAlgo(bondiola)55            //6500 / 3 = 2166,6656            Organizacion.promedioGastadoPorParticipante().shouldBe(2166)57        }58        it("Zona vip mas concurrida"){59            participante3.compraEntradaSUPERFAN() // participante 3 puede entrar a los 3 vips60            participante1.comprarAlgo(bondiola) // participante 1 ya tenia entrada FAN, compra bondiola de 1000 y ahora puede acceder a 261                                                // participante 2 puede entrar a 2 por entrada REFAN62            participante1.entrarVip(Rock)63            participante2.entrarVip(Rock)64            participante3.entrarVip(Pop)65            participante3.entrarVip(Trap)66            Organizacion.escenarioVipMasVisitado().shouldBe(Rock)67            participante2.entrarVip(Pop)68            participante1.entrarVip(Pop)69            Organizacion.escenarioVipMasVisitado().shouldBe(Pop)70        }71        it("Promedio de cc de alcohol de los participantes que tomaron alcohol"){72            participante2.comprarAlgo(cerveza)73            participante2.comprarAlgo(cerveza)74            participante2.comprarAlgo(milkshake)75            participante3.comprarAlgo(bebidaFuerte)76            // participante1 es menor, no puede consumir alcohol77            // participante2 tomo 40 cc de alcohol por las 2 cervezas78            // participante3 tomo 80 cc de alcohol solo por la bebida fuerte79            // el promedio debería ser (40+80)/2= 6080            Organizacion.promedioCCAlcohol().shouldBe(60)81            participante2.comprarAlgo(cerveza)82            //ahora debería dar 140/2 = 7083            Organizacion.promedioCCAlcohol().shouldBe(70)84        }85        it("Porcentaje del total de participantes que llegaron a 80cc"){86            participante3.comprarAlgo(bebidaFuerte)87            // 1 de 3 llegao a 80 cc, debería dar 33,3388            Organizacion.porcentajeTomaron80cc().shouldBe(33)89            participante2.comprarAlgo(cerveza)90            participante2.comprarAlgo(cerveza)91            participante2.comprarAlgo(cerveza)92            participante2.comprarAlgo(cerveza)93            // 2 de 3 llegaron a 80 cc, debería dar 66,6694            Organizacion.porcentajeTomaron80cc().shouldBe(66)95        }96        it("Porcentaje de los participantes que no tomaron alcohol"){97            participante3.comprarAlgo(cerveza)98            // Debería dar 66,6699            Organizacion.porcentajeNoTomaron().shouldBe(66)100            participante2.comprarAlgo(cerveza)101            // Debería dar 33,33102            Organizacion.porcentajeNoTomaron().shouldBe(33)103        }104        it("Porcentaje veganos"){105            participante1.comprarAlgo(bondiola)106            Organizacion.porcentajeVeganos().shouldBe(66)107            participante2.comprarAlgo(bondiola)108            Organizacion.porcentajeVeganos().shouldBe(33)109            participante3.comprarAlgo(bondiola)110            Organizacion.porcentajeVeganos().shouldBe(0)111        }112        it("Bebida mas consumida"){113            shouldThrowAny { // todavía no se realizaron ventas114                Organizacion.bebidaMasConsumida()115            }116            participante1.comprarAlgo(milkshake)117            participante1.comprarAlgo(milkshake)118            participante1.comprarAlgo(milkshake)119            participante2.comprarAlgo(cerveza)120            participante3.comprarAlgo(cerveza)121            // Hasta aca lo mas vendido es el milkshake122            Organizacion.bebidaMasConsumida().shouldBe(milkshake)123            participante2.comprarAlgo(cerveza)124            participante3.comprarAlgo(cerveza)125            // Ahora se vendió mas cerveza126            Organizacion.bebidaMasConsumida().shouldBe(cerveza)127            participante2.comprarAlgo(milkshake)128            // Si hay dos que se vendieron lo mismo creo que arroja el primero por orden alfabético129            Organizacion.bebidaMasConsumida().shouldBe(cerveza)130        }131        it("Bebida mas vendida a una hora especifica"){132            // No se como testear esto133            participante1.comprarAlgo(bondiola)134            participante2.comprarAlgo(bondiolaVegana)135            participante3.comprarAlgo(bondiola)136            shouldThrowAny { // Todavía no se registró venta de bebidas137                Organizacion.bebidaMasConsumidaAUnaHoraDeterminada(LocalDateTime.now().minusMinutes(30))138            }139            participante2.comprarAlgo(cerveza)140            participante2.comprarAlgo(cerveza)141            participante3.comprarAlgo(bebidaFuerte)142            participante1.comprarAlgo(milkshake)143            // Nos devuelve cerveza como la mas vendida144            Organizacion.bebidaMasConsumidaAUnaHoraDeterminada(LocalDateTime.now().minusMinutes(30)).shouldBe(cerveza)145            shouldThrowAny { // Cuando corro el test se registran las ventas. Si pregunto por las ventas de hace 3 horas arroja error.146                Organizacion.bebidaMasConsumidaAUnaHoraDeterminada(LocalDateTime.now().minusHours(3))147            }148        }149        it("Dos participantes con la misma onda"){150            // participante 1 tiene como artistas favoritos a Sumados, Trueno y Tini151            // participante 2 tiene como artistas favoritos a Trueno, Wos y Abel Pintos152            // participante 3 tiene como artistas favoritos a JNT , Sumados Y Wos153            // participante 4 tiene como artistas favoritos a JNT, Sumados y Trueno154            // Debería ser cierto porque tienen 2 artistas favoritos en común155            Organizacion.dosPersonasTienenLaMismaOnda(participante3, participante4).shouldBe(true)156            // No debería ser cierto157            Organizacion.dosPersonasTienenLaMismaOnda(participante1, participante2).shouldBe(false)158            participante2.entrarVip(Rock)159            participante1.entrarVip(Rock)160            161            // Debería ser cierto porque ingresaron a alguna zona vip dentro de la misma hora162            Organizacion.dosPersonasTienenLaMismaOnda(participante1, participante2).shouldBe(true)163        }164        Organizacion.foodTrucks.clear()165        Organizacion.registroIngresos.clear()166    }167})...

Full Screen

Full Screen

LocalDateTimeTests.kt

Source:LocalDateTimeTests.kt Github

copy

Full Screen

1package io.kotest.matchers.kotlinx.datetime2import io.kotest.assertions.shouldFail3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNot7import io.kotest.matchers.shouldNotBe8import kotlinx.datetime.Clock9import kotlinx.datetime.DayOfWeek10import kotlinx.datetime.LocalDate11import kotlinx.datetime.LocalDateTime12import kotlinx.datetime.Month13import kotlinx.datetime.TimeZone14import kotlinx.datetime.toLocalDateTime15import kotlinx.datetime.todayAt16import kotlin.time.days17class LocalDateTimeTests : StringSpec({18    "LocalDateTime should have same year ignoring other fields" {19        LocalDateTime(2014, 1, 2, 4, 3, 2) should haveSameYear(LocalDateTime(2014, 5, 6, 3, 2, 1))20        LocalDateTime(2014, 1, 2, 3, 2, 1) shouldNot haveSameYear(LocalDateTime(2018, 5, 6, 3, 2, 1))21        LocalDateTime(2014, 1, 2, 4, 3, 2).shouldHaveSameYearAs(LocalDateTime(2014, 5, 6, 3, 2, 1))22        LocalDateTime(2014, 1, 2, 3, 2, 1).shouldNotHaveSameYearAs(LocalDateTime(2018, 5, 6, 3, 2, 1))23    }24    "LocalDate should have same month ignoring other fields" {25        LocalDate(2014, 1, 2) should haveSameMonth(LocalDate(2016, 1, 6))26        LocalDate(2014, 1, 2) shouldNot haveSameMonth(LocalDate(2018, 4, 6))27        LocalDate(2014, 1, 2).shouldHaveSameMonthAs(LocalDate(2016, 1, 6))28        LocalDate(2014, 1, 2).shouldNotHaveSameMonthAs(LocalDate(2018, 4, 6))29    }30    "LocalDateTime should have same month ignoring other fields" {31        LocalDateTime(2014, 1, 2, 4, 3, 2) should haveSameMonth(LocalDateTime(2014, 1, 6, 3, 2, 1))32        LocalDateTime(2014, 1, 2, 3, 2, 1) shouldNot haveSameMonth(LocalDateTime(2018, 2, 6, 3, 2, 1))33        LocalDateTime(2014, 1, 2, 4, 3, 2).shouldHaveSameMonthAs(LocalDateTime(2014, 1, 6, 3, 2, 1))34        LocalDateTime(2014, 1, 2, 3, 2, 1).shouldNotHaveSameMonthAs(LocalDateTime(2018, 2, 6, 3, 2, 1))35    }36    "LocalDate should have same day ignoring other fields" {37        LocalDate(2014, 1, 2) should haveSameDay(LocalDate(2014, 1, 2))38        LocalDate(2014, 1, 2) shouldNot haveSameDay(LocalDate(2014, 4, 6))39        LocalDate(2014, 1, 2).shouldHaveSameDayAs(LocalDate(2014, 1, 2))40        LocalDate(2014, 1, 2).shouldNotHaveSameDayAs(LocalDate(2014, 4, 6))41    }42    "LocalDateTime should have same day ignoring other fields" {43        LocalDateTime(2014, 1, 2, 4, 3, 2) should haveSameDay(LocalDateTime(2014, 1, 2, 3, 2, 1))44        LocalDateTime(2014, 1, 2, 3, 2, 1) shouldNot haveSameDay(LocalDateTime(2014, 2, 6, 3, 2, 1))45        LocalDateTime(2014, 1, 2, 4, 3, 2).shouldHaveSameDayAs(LocalDateTime(2014, 1, 2, 3, 2, 1))46        LocalDateTime(2014, 1, 2, 3, 2, 1).shouldNotHaveSameDayAs(LocalDateTime(2014, 2, 6, 3, 2, 1))47    }48    "LocalDate shouldBe before" {49        LocalDate(2014, 1, 2) shouldBe before(LocalDate(2014, 1, 3))50        LocalDate(2014, 1, 2) shouldNotBe before(LocalDate(2014, 1, 1))51        LocalDate(2014, 1, 2).shouldBeBefore(LocalDate(2014, 1, 3))52        LocalDate(2014, 1, 2).shouldNotBeBefore(LocalDate(2014, 1, 1))53    }54    "LocalDateTime shouldBe before" {55        LocalDateTime(2014, 1, 2, 4, 3, 2) shouldBe before(LocalDateTime(2014, 2, 2, 3, 2, 1))56        LocalDateTime(2014, 1, 2, 3, 2, 1) shouldNotBe before(LocalDateTime(2014, 1, 1, 3, 2, 1))57        LocalDateTime(2014, 1, 2, 4, 3, 2).shouldBeBefore(LocalDateTime(2014, 2, 2, 3, 2, 1))58        LocalDateTime(2014, 1, 2, 3, 2, 1).shouldNotBeBefore(LocalDateTime(2014, 1, 1, 3, 2, 1))59    }60    "LocalDate shouldBe after" {61        LocalDate(2014, 1, 2) shouldBe after(LocalDate(2013, 1, 3))62        LocalDate(2014, 1, 2) shouldNotBe after(LocalDate(2014, 1, 3))63        LocalDate(2014, 1, 2).shouldBeAfter(LocalDate(2013, 1, 3))64        LocalDate(2014, 1, 2).shouldNotBeAfter(LocalDate(2014, 1, 3))65    }66    "LocalDateTime shouldBe after" {67        LocalDateTime(2014, 1, 2, 4, 3, 2) shouldBe after(LocalDateTime(2014, 1, 1, 3, 2, 1))68        LocalDateTime(2014, 1, 2, 3, 2, 1) shouldNotBe after(LocalDateTime(2014, 1, 3, 3, 2, 1))69        LocalDateTime(2014, 1, 2, 4, 3, 2).shouldBeAfter(LocalDateTime(2014, 1, 1, 3, 2, 1))70        LocalDateTime(2014, 1, 2, 3, 2, 1).shouldNotBeAfter(LocalDateTime(2014, 1, 3, 3, 2, 1))71    }72    "LocalDateTime shouldBe between" {73        LocalDateTime(2019, 2, 16, 12, 0, 0).shouldBeBetween(LocalDateTime(2019, 2, 15, 12, 0, 0), LocalDateTime(2019, 2, 17, 12, 0, 0))74        LocalDateTime(2019, 2, 16, 12, 0, 0).shouldBeBetween(LocalDateTime(2019, 2, 16, 10, 0, 0), LocalDateTime(2019, 2, 16, 14, 0, 0))75        LocalDateTime(2019, 2, 16, 12, 0, 0).shouldNotBeBetween(LocalDateTime(2019, 2, 17, 12, 0, 0), LocalDateTime(2019, 2, 18, 12, 0, 0))76        LocalDateTime(2019, 2, 16, 12, 0, 0).shouldNotBeBetween(LocalDateTime(2019, 2, 16, 18, 0, 0), LocalDateTime(2019, 2, 16, 20, 0, 0))77    }78    "LocalDate.shouldBeToday() should match today" {79        Clock.System.todayAt(TimeZone.UTC).shouldBeToday(TimeZone.UTC)80    }81    "LocalDateTime.shouldBeToday() should match today" {82        Clock.System.todayAt(TimeZone.UTC).shouldBeToday(TimeZone.UTC)83    }84    "LocalDate.shouldBeToday() should not match the past" {85        shouldFail {86            LocalDate(2002, Month.APRIL, 1).shouldBeToday(TimeZone.UTC)87        }88    }89    "LocalDateTime.shouldBeToday() should not match the past" {90        shouldFail {91            LocalDateTime(2002, Month.APRIL, 1, 5, 2).shouldBeToday(TimeZone.UTC)92        }93        shouldFail {94            Clock.System.now().minus(1.days).toLocalDateTime(TimeZone.UTC).shouldBeToday(TimeZone.UTC)95        }96    }97    "LocalDateTime.shouldNotBeToday()" {98        LocalDateTime(2002, Month.APRIL, 1, 5, 2).shouldNotBeToday(TimeZone.UTC)99        shouldFail {100            Clock.System.todayAt(TimeZone.UTC).shouldNotBeToday(TimeZone.UTC)101        }102    }103    "LocalDate.shouldNotBeToday()" {104        LocalDate(2002, Month.APRIL, 2).shouldNotBeToday()105        shouldFail {106            Clock.System.todayAt(TimeZone.UTC).shouldNotBeToday(TimeZone.UTC)107        }108    }109    "LocalDateTime should have day of month (day)" {110        LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfMonth 16111    }112    "LocalDateTime should have day of week" {113        LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfWeek DayOfWeek.SATURDAY114        LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfWeek  6115    }116    "LocalDateTime should have day of year" {117        LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfYear  47118    }119    "LocalDateTime should have month" {120        LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveMonth 2121        LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveMonth Month.FEBRUARY122    }123    "LocalDateTime should have hour" {124        LocalDateTime(2019, 2, 16, 12, 10, 0, 0) shouldHaveHour 12125    }126    "LocalDateTime should have minute" {127        LocalDateTime(2019, 2, 16, 12, 10, 0, 0) shouldHaveMinute 10128    }129    "LocalDateTime should have second" {130        LocalDateTime(2019, 2, 16, 12, 10, 13, 0) shouldHaveSecond  13131    }132    "LocalDateTime should have nano" {133        LocalDateTime(2019, 2, 16, 12, 10, 0, 14) shouldHaveNano  14134    }135})...

Full Screen

Full Screen

LocalDateTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1val date = LocalDateTime.of(2019, 1, 1, 0, 0, 0)2date.shouldBeBetween(LocalDateTime.of(2018, 12, 31, 0, 0, 0),3LocalDateTime.of(2019, 1, 2, 0, 0, 0))4val date = LocalDateTime.of(2019, 1, 1, 0, 0, 0)5date.shouldBeBetween(LocalDateTime.of(2018, 12, 31, 0, 0, 0),6LocalDateTime.of(2019, 1, 2, 0, 0, 0))7val date = LocalDateTime.of(2019, 1, 1, 0, 0, 0)8date.shouldBeBetween(LocalDateTime.of(2018, 12, 31, 0, 0, 0),9LocalDateTime.of(2019, 1, 2, 0, 0, 0))10val date = LocalDateTime.of(2019, 1, 1, 0, 0, 0)11date.shouldBeBetween(LocalDateTime.of(2018, 12, 31, 0, 0, 0),12LocalDateTime.of(2019, 1, 2, 0, 0, 0))13val date = LocalDateTime.of(2019, 1, 1, 0, 0, 0)14date.shouldBeBetween(LocalDateTime.of(2018, 12, 31, 0, 0, 0),15LocalDateTime.of(2019, 1, 2, 0, 0, 0))16val date = LocalDateTime.of(2019, 1, 1, 0, 0, 0)17date.shouldBeBetween(LocalDateTime.of(201

Full Screen

Full Screen

LocalDateTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1val date = LocalDateTime.of(2017, 10, 31, 0, 0)2date.shouldBeBetween(LocalDateTime.of(2017, 10, 30, 0, 0), LocalDateTime.of(2017, 10, 31, 0, 0))3val date = LocalDateTime.of(2017, 10, 31, 0, 0)4date.shouldBeBetween(LocalDateTime.of(2017, 10, 30, 0, 0), LocalDateTime.of(2017, 10, 31, 0, 0))5val date = LocalDateTime.of(2017, 10, 31, 0, 0)6date.shouldBeBetween(LocalDateTime.of(2017, 10, 30, 0, 0), LocalDateTime.of(2017, 10, 31, 0, 0))7val date = LocalDateTime.of(2017, 10, 31, 0, 0)8date.shouldBeBetween(LocalDateTime.of(2017, 10, 30, 0, 0), LocalDateTime.of(2017, 10, 31, 0, 0))9val date = LocalDateTime.of(2017, 10, 31, 0, 0)10date.shouldBeBetween(LocalDateTime.of(2017, 10, 30, 0, 0), LocalDateTime.of(2017, 10, 31, 0, 0))11val date = LocalDateTime.of(2017, 10, 31, 0, 0)12date.shouldBeBetween(LocalDateTime.of(2017, 10, 30, 0, 0), LocalDateTime.of(2017, 10, 31, 0, 0))

Full Screen

Full Screen

LocalDateTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.date.shouldBeBetween2import java.time.LocalDateTime3val date = LocalDateTime.now()4date.shouldBeBetween(date.minusDays(1), date.plusDays(1))5import io.kotest.matchers.date.shouldBeBefore6import java.time.LocalDateTime7val date = LocalDateTime.now()8date.shouldBeBefore(date.plusDays(1))9import io.kotest.matchers.date.shouldBeAfter10import java.time.LocalDateTime11val date = LocalDateTime.now()12date.shouldBeAfter(date.minusDays(1))13import io.kotest.matchers.date.shouldBeSameOrBefore14import java.time.LocalDateTime15val date = LocalDateTime.now()16date.shouldBeSameOrBefore(date.plusDays(1))17date.shouldBeSameOrBefore(date)18import io.kotest.matchers.date.shouldBeSameOrAfter19import java.time.LocalDateTime20val date = LocalDateTime.now()21date.shouldBeSameOrAfter(date.minusDays(1))22date.shouldBeSameOrAfter(date)23import io.kotest.matchers.date.shouldBeBetweenInclusive24import java.time.LocalDateTime25val date = LocalDateTime.now()26date.shouldBeBetweenInclusive(date.minusDays(1), date.plusDays(1))27import io.kotest.matchers.date.shouldBeBetweenExclusive28import java.time.LocalDateTime29val date = LocalDateTime.now()30date.shouldBeBetweenExclusive(date.minusDays(1), date.plusDays(1))31import io.kotest.matchers.date.shouldBeBetweenInclusiveStart32import java.time.LocalDateTime33val date = LocalDateTime.now()34date.shouldBeBetweenInclusiveStart(date.minusDays(1), date.plusDays(1))

Full Screen

Full Screen

LocalDateTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1@DisplayName("LocalDateTime shouldBeBetween Test")2class LocalDateTimeShouldBeBetweenTest {3    fun `LocalDateTime shouldBeBetween should pass if the LocalDateTime is between two other LocalDateTime objects`() {4        LocalDateTime.now().shouldBeBetween(LocalDateTime.now().minusDays(1), LocalDateTime.now().plusDays(1))5    }6    fun `LocalDateTime shouldBeBetween should fail if the LocalDateTime is not between two other LocalDateTime objects`() {7        shouldThrow<AssertionError> {8            LocalDateTime.now().shouldBeBetween(LocalDateTime.now().plusDays(1), LocalDateTime.now().plusDays(2))9        }10    }11}12@DisplayName("LocalDateTime shouldNotBeBetween Test")13class LocalDateTimeShouldNotBeBetweenTest {14    fun `LocalDateTime shouldNotBeBetween should pass if the LocalDateTime is not between two other LocalDateTime objects`() {15        LocalDateTime.now().shouldNotBeBetween(LocalDateTime.now().plusDays(1), LocalDateTime.now().plusDays(2))16    }17    fun `LocalDateTime shouldNotBeBetween should fail if the LocalDateTime is between two other LocalDateTime objects`() {18        shouldThrow<AssertionError> {19            LocalDateTime.now().shouldNotBeBetween(LocalDateTime.now().minusDays(1), LocalDateTime.now().plusDays(1))20        }21    }22}23@DisplayName("LocalDateTime shouldBeAfter Test")24class LocalDateTimeShouldBeAfterTest {25    fun `LocalDateTime shouldBeAfter should pass if the LocalDateTime is after the other LocalDateTime object`() {26        LocalDateTime.now().shouldBeAfter(LocalDateTime.now().minusDays(1))27    }28    fun `LocalDateTime shouldBeAfter should fail if the LocalDateTime is not after the other LocalDateTime object`() {29        shouldThrow<AssertionError> {30            LocalDateTime.now().shouldBeAfter(LocalDateTime.now().plusDays(1))31        }32    }33}34@DisplayName("LocalDateTime shouldBeAfterOrEqual Test")

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