How to use LocalDate.shouldBeToday method of io.kotest.matchers.date.localdatetime class

Best Kotest code snippet using io.kotest.matchers.date.localdatetime.LocalDate.shouldBeToday

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

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

today.kt

Source:today.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.shouldNot6import kotlinx.datetime.*7/**8 * Matcher that checks if a LocalDateTime has a Date component of today9 *10 * It does this by checking it against Current Time, so if you are not using constant now listeners,11 * using this might fail if test run exactly on a date change.12 *13 * ```14 * val date = Clock.System().todayAt(TimeZone.UTC)15 *16 * date should beInToday() // Assertion passes17 *18 *19 * val date = LocalDateTime(2018, Month.APRIL, 1, 3, 5)20 *21 * date should beInToday() // Assertion fails22 * ```23 */24fun beInToday(timezone: TimeZone = TimeZone.UTC) = object : Matcher<LocalDateTime> {25 override fun test(value: LocalDateTime): MatcherResult {26 val passed = value.date == Clock.System.todayAt(timezone)27 return MatcherResult(28 passed,29 "$value should be today",30 "$value should not be today"31 )32 }33}34/**35 * Matcher that checks if a LocalDate is today36 *37 * It does this by checking it against current time, so if you are not using constant now listeners,38 * using this might fail if test run exactly on a date change.39 *40 * ```41 * val date = Clock.System().todayAt(TimeZone.UTC).date42 *43 * date should beToday() // Assertion passes44 *45 *46 * val date = LocalDate(2018,1,1)47 *48 * date should beToday() // Assertion fails49 * ```50 */51fun beToday(timezone: TimeZone = TimeZone.UTC) = object : Matcher<LocalDate> {52 override fun test(value: LocalDate): MatcherResult {53 val passed = value == Clock.System.todayAt(timezone)54 return MatcherResult(55 passed,56 "$value should be today",57 "$value should not be today"58 )59 }60}61/**62 * Asserts that the LocalDateTime has a date component of today63 *64 * ```65 * Clock.System().todayAt(TimeZone.UTC).shouldBeToday() // Assertion passes66 * ```67 */68fun LocalDateTime.shouldBeToday(timezone: TimeZone = TimeZone.UTC) = this should beInToday(timezone)69/**70 * Asserts that the LocalDate is today71 *72 * ```73 * Clock.System().todayAt(TimeZone.UTC).date.shouldBeToday() // Assertion passes74 * ```75 */76fun LocalDate.shouldBeToday(timezone: TimeZone = TimeZone.UTC) = this should beToday(timezone)77/**78 * Asserts that the LocalDateTime does not have a date component of today79 *80 * ```81 * LocalDateTime(2009, Month.APRIL, 2,2,2).shouldNotBeToday() // Assertion passes82 * ```83 */84fun LocalDateTime.shouldNotBeToday(timezone: TimeZone = TimeZone.UTC) = this shouldNot beInToday(timezone)85/**86 * Asserts that the LocalDate is not today87 *88 * ```89 * LocalDate(2009, Month.APRIL, 2).shouldNotBeToday() // Assertion passes90 * ```91 */92fun LocalDate.shouldNotBeToday(timezone: TimeZone = TimeZone.UTC) = this shouldNot beToday(timezone)...

Full Screen

Full Screen

localdatetime.kt

Source:localdatetime.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.shouldNot6import java.time.LocalDate7import java.time.LocalDateTime8/**9 * Matcher that checks if a LocalDateTime has a Date component of today10 *11 * It does this by checking it against LocalDate.now(), so if you are not using constant now listeners,12 * using this might fail if test run exactly on a date change.13 *14 * ```15 * val date = LocalDateTime.now()16 *17 * date should beInToday() // Assertion passes18 *19 *20 * val date = LocalDateTime.of(2018, Month.APRIL, 1, 3, 5)21 *22 * date should beInToday() // Assertion fails23 * ```24 */25fun beInToday() = object : Matcher<LocalDateTime> {26 override fun test(value: LocalDateTime): MatcherResult {27 val passed = value.toLocalDate() == LocalDate.now()28 return MatcherResult(29 passed,30 { "$value should be today" },31 {32 "$value should not be today"33 })34 }35}36/**37 * Matcher that checks if a LocalDate is today38 *39 * It does this by checking it against LocalDate.now(), so if you are not using constant now listeners,40 * using this might fail if test run exactly on a date change.41 *42 * ```43 * val date = LocalDate.now()44 *45 * date should beToday() // Assertion passes46 *47 *48 * val date = LocalDate.of(2018,1,1)49 *50 * date should beToday() // Assertion fails51 * ```52 */53fun beToday() = object : Matcher<LocalDate> {54 override fun test(value: LocalDate): MatcherResult {55 val passed = value == LocalDate.now()56 return MatcherResult(57 passed,58 { "$value should be today" },59 {60 "$value should not be today"61 })62 }63}64/**65 * Asserts that the LocalDateTime has a date component of today66 *67 * ```68 * LocalDateTime.now().shouldBeToday() // Assertion passes69 * ```70 */71fun LocalDateTime.shouldBeToday() = this should beInToday()72/**73 * Asserts that the LocalDate is today74 *75 * ```76 * LocalDate.now().shouldBeToday() // Assertion passes77 * ```78 */79fun LocalDate.shouldBeToday() = this should beToday()80/**81 * Asserts that the LocalDateTime does not have a date component of today82 *83 * ```84 * LocalDateTime.of(2009, Month.APRIL, 2,2,2).shouldNotBeToday() // Assertion passes85 * ```86 */87fun LocalDateTime.shouldNotBeToday() = this shouldNot beInToday()88/**89 * Asserts that the LocalDate is not today90 *91 * ```92 * LocalDate.of(2009, Month.APRIL, 2).shouldNotBeToday() // Assertion passes93 * ```94 */95fun LocalDate.shouldNotBeToday() = this shouldNot beToday()...

Full Screen

Full Screen

LocalDate.shouldBeToday

Using AI Code Generation

copy

Full Screen

1localDateTime.shouldBeToday()2localDateTime.shouldBeTomorrow()3localDateTime.shouldBeYesterday()4localDateTime.shouldBeBetween(before, after)5localDateTime.shouldBeBetweenClosed(before, after)6localDateTime.shouldBeBetweenOpen(before, after)7localDateTime.shouldBeBefore(before)8localDateTime.shouldBeAfter(after)9localDateTime.shouldBeInThePast()10localDateTime.shouldBeInTheFuture()11localDateTime.shouldBeInSameDayAs(other)12localDateTime.shouldBeInSameMonthAs(other)13localDateTime.shouldBeInSameYearAs(other)14localDateTime.shouldBeInSameHourAs(other)15localDateTime.shouldBeInSameMinuteAs(other)16localDateTime.shouldBeInSameSecondAs(other)

Full Screen

Full Screen

LocalDate.shouldBeToday

Using AI Code Generation

copy

Full Screen

1val date = LocalDate.now()2val date = LocalDate.now()3val date = LocalDate.now()4val date = LocalDate.now()5val date = LocalDate.now()6val date = LocalDate.now()7val date = LocalDate.now()8val date = LocalDate.now()9val date = LocalDate.now()10val date = LocalDate.now()11val date = LocalDate.now()12val date = LocalDate.now()13val date = LocalDate.now()14val date = LocalDate.now()

Full Screen

Full Screen

LocalDate.shouldBeToday

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.date.localdatetime.shouldBeToday2import java.time.LocalDate3val today = LocalDate.now()4import io.kotest.matchers.date.localdate.shouldBeToday5import java.time.LocalDate6val today = LocalDate.now()7import io.kotest.matchers.date.localdatetime.shouldBeToday8import java.time.LocalDate9val today = LocalDate.now()10import io.kotest.matchers.date.localdate.shouldBeToday11import java.time.LocalDate12val today = LocalDate.now()13import io.kotest.matchers.date.localdatetime.shouldBeToday14import java.time.LocalDate15val today = LocalDate.now()16import io.kotest.matchers.date.localdate.shouldBeToday17import java.time.LocalDate18val today = LocalDate.now()19import io.kotest.matchers.date.localdatetime.shouldBeToday20import java.time.LocalDate

Full Screen

Full Screen

LocalDate.shouldBeToday

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.date.localdatetime.shouldBeToday2import io.kotest.matchers.date.localdatetime.shouldBeTomorrow3import io.kotest.matchers.date.localdatetime.shouldBeYesterday4import io.kotest.matchers.date.localdatetime.shouldBeWithin5import io.kotest.matchers.date.localdatetime.shouldBeWithin6import io.kotest.matchers.date.localdatetime.shouldBeWithin7import io.kotest.matchers.date.localdatetime.shouldBeWithin8import io.kotest.matchers.date.localdatetime.shouldBeWithin9import io.kotest.matchers.date.localdatetime.should

Full Screen

Full Screen

LocalDate.shouldBeToday

Using AI Code Generation

copy

Full Screen

1"should be today" {2val today = LocalDate.now()3today.shouldBeToday()4}5"should be today" {6val today = LocalDate.now()7today.shouldBeToday()8}9"should be today" {10val today = LocalDate.now()11today.shouldBeToday()12}13"should be today" {14val today = LocalDate.now()15today.shouldBeToday()16}17"should be today" {18val today = LocalDate.now()19today.shouldBeToday()20}21"should be today" {22val today = LocalDate.now()23today.shouldBeToday()24}25"should be today" {26val today = LocalDate.now()27today.shouldBeToday()28}29"should be today" {30val today = LocalDate.now()31today.shouldBeToday()32}33"should be today" {34val today = LocalDate.now()35today.shouldBeToday()36}37"should be today" {38val today = LocalDate.now()39today.shouldBeToday()40}41"should be today" {42val today = LocalDate.now()43today.shouldBeToday()44}

Full Screen

Full Screen

LocalDate.shouldBeToday

Using AI Code Generation

copy

Full Screen

1@DisplayName ( "Test for LocalDate.shouldBeToday" ) @Test fun testShouldBeToday () { val today = LocalDate . now () today . shouldBeToday () }2@DisplayName ( "Test for LocalDate.shouldNotBeToday" ) @Test fun testShouldNotBeToday () { val today = LocalDate . now () val tomorrow = today . plusDays ( 1 ) tomorrow . shouldNotBeToday () }3@DisplayName ( "Test for LocalDate.shouldBeWeekend" ) @Test fun testShouldBeWeekend () { val today = LocalDate . now () today . shouldBeWeekend () }4@DisplayName ( "Test for LocalDate.shouldBeWeekday" ) @Test fun testShouldBeWeekday () { val today = LocalDate . now () today . shouldBeWeekday () }5@DisplayName ( "Test for LocalDate.shouldBeInYear" ) @Test fun testShouldBeInYear () { val today = LocalDate . now () today . shouldBeInYear ( 2021 ) }6@DisplayName ( "Test for LocalDate.shouldBeInMonth" ) @Test fun testShouldBeInMonth () { val today = LocalDate . now () today . shouldBeInMonth ( Month . MAY ) }7@DisplayName ( "Test for LocalDate.shouldBeInMonth" ) @Test fun testShouldBeInMonth () { val today = LocalDate . now () today . shouldBeInMonth ( Month . MAY ) }

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.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful