Skip to content

Commit

Permalink
removing klock
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Jul 16, 2023
1 parent 174ed69 commit acebbfa
Show file tree
Hide file tree
Showing 115 changed files with 524 additions and 469 deletions.
1 change: 0 additions & 1 deletion client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ dependencies {
jsMainImplementation(project(":libraries:repository:core"))
jsMainImplementation(project(":libraries:repository:memory"))
jsMainImplementation("com.benasher44:uuid")
jsMainImplementation("com.soywiz.korlibs.klock:klock")
jsMainImplementation("com.zegreatrob.jsmints:minreact")
jsMainImplementation("com.zegreatrob.jsmints:react-data-loader")
jsMainImplementation("com.zegreatrob.testmints:action")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import com.zegreatrob.minreact.ReactFunc
import com.zegreatrob.minreact.nfc
import emotion.css.ClassName
import emotion.react.css
import korlibs.time.DateFormat
import korlibs.time.DateTimeTz
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import react.ChildrenBuilder
import react.Props
import react.dom.html.ReactHTML.div
Expand Down Expand Up @@ -152,6 +153,6 @@ private fun ChildrenBuilder.showPlayer(pinnedPlayer: PinnedPlayer) = span {
}
}

fun PairAssignmentDocument.dateText() = date.local.dateText()
fun PairAssignmentDocument.dateText() = date.toLocalDateTime(TimeZone.currentSystemDefault()).dateText()

private fun DateTimeTz.dateText() = "${format(DateFormat("MM/dd/YYYY"))} - ${format(DateFormat("HH:mm:ss"))}"
private fun LocalDateTime.dateText() = "$date - $time"
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ val PartyStatistics by nfc<PartyStatisticsProps> { props ->
spinsUntilFullRotation = spinsUntilFullRotation,
activePlayerCount = players.size,
medianSpinDuration = medianSpinDuration?.let {
formatDistance(medianSpinDuration.millisecondsInt, 0)
formatDistance(medianSpinDuration.inWholeMilliseconds.toInt(), 0)
} ?: "",
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.waitFor
import com.zegreatrob.wrapper.testinglibrary.userevent.UserEvent
import js.core.jso
import korlibs.time.DateTime
import kotlinx.datetime.Clock
import org.w3c.dom.HTMLElement
import org.w3c.dom.asList
import org.w3c.dom.get
Expand Down Expand Up @@ -140,7 +140,7 @@ class PrepareSpinTest {
val user = UserEvent.setup()
val currentPairs = PairAssignmentDocument(
PairAssignmentDocumentId(""),
DateTime.now(),
Clock.System.now(),
listOf(
pairOf(players[0], players[1]).withPins(emptySet()),
pairOf(players[2]).withPins(emptySet()),
Expand Down Expand Up @@ -194,7 +194,7 @@ class PrepareSpinTest {
val players = stubPlayers(3)
val currentPairs = PairAssignmentDocument(
id = PairAssignmentDocumentId("${uuid4()}"),
date = DateTime.now(),
date = Clock.System.now(),
pairs = players.map { pairOf(it).withPins(emptySet()) },
)
val context = render(jso { wrapper = MemoryRouter }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.waitFor
import com.zegreatrob.wrapper.testinglibrary.userevent.UserEvent
import js.core.jso
import korlibs.time.DateTime
import kotlinx.datetime.Clock
import react.ReactNode
import react.create
import react.router.RouterProvider
Expand All @@ -32,7 +32,7 @@ class CurrentPairAssignmentsPanelTest {
val party = stubPartyDetails()
val pairAssignments = PairAssignmentDocument(
id = PairAssignmentDocumentId("${uuid4()}"),
date = DateTime.now(),
date = Clock.System.now(),
pairs = emptyList(),
)
val stubDispatcher = OldStubDispatcher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.render
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.userevent.UserEvent
import js.core.jso
import korlibs.time.DateTime
import kotlinx.datetime.Clock
import org.w3c.dom.Window
import react.router.MemoryRouter
import kotlin.js.json
Expand All @@ -30,7 +30,7 @@ class PairAssignmentRowTest {
override val window: Window get() = json("confirm" to { true }).unsafeCast<Window>()
val party = PartyDetails(PartyId("me"))
val reloadSpy = SpyData<Unit, Unit>()
val document = PairAssignmentDocument(PairAssignmentDocumentId("RealId"), DateTime.now(), emptyList())
val document = PairAssignmentDocument(PairAssignmentDocumentId("RealId"), Clock.System.now(), emptyList())
val stubDispatcher = OldStubDispatcher()
val actor = UserEvent.setup()
}) {
Expand Down Expand Up @@ -59,7 +59,7 @@ class PairAssignmentRowTest {
val reloadSpy = SpyData<Unit, Unit>()
val document = PairAssignmentDocument(
PairAssignmentDocumentId("RealId"),
DateTime.now(),
Clock.System.now(),
emptyList(),
)
val stubDispatcher = OldStubDispatcher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.zegreatrob.testmints.async.asyncSetup
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.render
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import js.core.jso
import korlibs.time.DateTime
import kotlinx.datetime.Clock
import org.w3c.dom.HTMLElement
import org.w3c.dom.asList
import react.router.MemoryRouter
Expand All @@ -39,7 +39,7 @@ class PairAssignmentsTest {

var pairAssignments = PairAssignmentDocument(
id = PairAssignmentDocumentId("${uuid4()}"),
date = DateTime.now(),
date = Clock.System.now(),
pairs = listOf(
pairOf(
Player(id = "0", name = "Tom", avatarType = null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.render
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.within
import js.core.jso
import korlibs.time.DateTime
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant
import org.w3c.dom.HTMLElement
import org.w3c.dom.asList
import react.router.MemoryRouter
Expand All @@ -41,7 +45,7 @@ class PartyStatisticsTest :
val history = listOf(
PairAssignmentDocument(
id = PairAssignmentDocumentId("${uuid4()}"),
date = DateTime.now(),
date = Clock.System.now(),
pairs = listOf<CouplingPair>(
pairOf(players[0], players[1]),
pairOf(players[2], players[3]),
Expand Down Expand Up @@ -95,7 +99,7 @@ class PartyStatisticsTest :
val history = listOf(
PairAssignmentDocument(
id = PairAssignmentDocumentId("${uuid4()}"),
date = DateTime.now(),
date = Clock.System.now(),
pairs = listOf(
pairOf(players[0], players[1]),
pairOf(players[2], players[3]),
Expand Down Expand Up @@ -158,15 +162,15 @@ class PartyStatisticsTest :
val history = listOf(
PairAssignmentDocument(
id = PairAssignmentDocumentId("${uuid4()}"),
date = DateTime(2017, 3, 14),
date = dateTime(2017, 3, 14),
pairs = listOf(
pairOf(players[0], players[1]),
pairOf(players[2], players[3]),
).withNoPins(),
),
PairAssignmentDocument(
id = PairAssignmentDocumentId("${uuid4()}"),
date = DateTime(2017, 3, 12),
date = dateTime(2017, 3, 12),
pairs = listOf(
pairOf(players[0], players[1]),
pairOf(players[2], players[3]),
Expand All @@ -184,6 +188,9 @@ class PartyStatisticsTest :
}
}

private fun dateTime(year: Int, month: Int, day: Int): Instant =
LocalDateTime(year, month, day, 0, 0, 0).toInstant(TimeZone.currentSystemDefault())

private fun List<CouplingPair>.withNoPins() = map { pair -> pair.toPinnedPair() }

private fun CouplingPair.toPinnedPair() = PinnedCouplingPair(toPinnedPlayers())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.coupling.model.party.PartyId
import com.zegreatrob.coupling.model.pin.Pin
import com.zegreatrob.coupling.model.player.Player
import korlibs.time.DateTime
import kotlinx.datetime.Clock
import popper.core.Placement
import web.cssom.ClassName

Expand Down Expand Up @@ -56,9 +56,9 @@ private val pins = listOf(
)

private val pairAssignments = PairAssignmentDocument(
PairAssignmentDocumentId(""),
DateTime.now(),
listOf(
id = PairAssignmentDocumentId(""),
date = Clock.System.now(),
pairs = listOf(
pairOf(player1, player4).withPins(emptySet()),
pairOf(player2, player5).withPins(pins.toSet()),
pairOf(player6).withPins(emptySet()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ import com.zegreatrob.coupling.repository.player.PlayerListGetDeleted
import com.zegreatrob.coupling.sdk.CouplingSdkDispatcher
import com.zegreatrob.coupling.sdk.gql.GraphQuery
import com.zegreatrob.testmints.action.ActionCannon
import korlibs.time.TimeProvider
import kotlinx.datetime.Clock
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromJsonElement

class MemoryRepositoryCatalog private constructor(
override val userId: String,
override val clock: TimeProvider,
override val clock: Clock,
override val partyRepository: PartyRepository,
override val playerRepository: PlayerEmailRepository,
override val pairAssignmentDocumentRepository: PairAssignmentDocumentRepository,
Expand Down Expand Up @@ -71,7 +71,7 @@ class MemoryRepositoryCatalog private constructor(
UserIdSyntax,
ClockSyntax {

constructor(userEmail: String, backend: LocalStorageRepositoryBackend, clock: TimeProvider) : this(
constructor(userEmail: String, backend: LocalStorageRepositoryBackend, clock: Clock) : this(
userEmail,
clock,
MemoryPartyRepository(userEmail, clock, backend.party),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.zegreatrob.coupling.model.party.PartyId
import com.zegreatrob.coupling.sdk.couplingSdk
import com.zegreatrob.coupling.sdk.defaultClient
import js.core.ReadonlyRecord
import korlibs.time.TimeProvider
import kotlinx.browser.window
import kotlinx.datetime.Clock
import org.w3c.dom.get
import react.Props
import web.url.URLSearchParams
Expand All @@ -35,7 +35,7 @@ class MasterCommander(private val getIdentityToken: suspend () -> String) : Comm
override fun getDispatcher(traceId: Uuid) = CommandDispatcher(
traceId = traceId,
sdk = if (window["inMemory"] == true) {
MemoryRepositoryCatalog("test-user", backend, TimeProvider)
MemoryRepositoryCatalog("test-user", backend, Clock.System)
.sdk
} else {
couplingSdk(getIdentityToken, defaultClient(getLocationAndBasename()))
Expand Down
1 change: 0 additions & 1 deletion coupling-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dependencies {
implementation(kotlin("gradle-plugin", libs.versions.kotlin.get()))
implementation(libs.com.fasterxml.jackson.core.jackson.databind)
implementation(libs.com.github.ben.manes.gradle.versions.plugin)
implementation(libs.com.soywiz.korlibs.klock)
implementation(libs.org.ajoberstar.grgit.gradle.plugin)
implementation(libs.org.apache.logging.log4j.log4j.core)
implementation(libs.org.apache.logging.log4j.log4j.iostreams)
Expand Down
1 change: 0 additions & 1 deletion coupling-plugins/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ org-jlleitschuh-gradle-ktlint = "11.0.0"
[libraries]
com-fasterxml-jackson-core-jackson-databind = "com.fasterxml.jackson.core:jackson-databind:2.15.2"
com-github-ben-manes-gradle-versions-plugin = "com.github.ben-manes:gradle-versions-plugin:0.47.0"
com-soywiz-korlibs-klock = "com.soywiz.korlibs.klock:klock:4.0.9"
com-zegreatrob-jsmints-jsmints-bom = "com.zegreatrob.jsmints:jsmints-bom:4.3.14"
com-zegreatrob-testmints-testmints-bom = "com.zegreatrob.testmints:testmints-bom:10.1.2"
com-zegreatrob-tools-tools-bom = "com.zegreatrob.tools:tools-bom:0.5.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.TextNode
import korlibs.time.TimeSpan
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
Expand All @@ -14,6 +13,8 @@ import org.gradle.api.tasks.testing.TestListener
import org.gradle.api.tasks.testing.TestOutputEvent
import org.gradle.api.tasks.testing.TestOutputListener
import org.gradle.api.tasks.testing.TestResult
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

class JsonLoggingTestListener(private val taskName: String, val testRunIdentifier: String) :
TestListener,
Expand All @@ -39,15 +40,15 @@ class JsonLoggingTestListener(private val taskName: String, val testRunIdentifie
private fun Map<String, String?>.asMessage() = ObjectMessage(this)

override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {
val durationLong = TimeSpan((result.endTime - result.startTime).toDouble())
val durationLong = (result.endTime - result.startTime).milliseconds
logger.info {
testInfo(testDescriptor)
.plus(afterTestInfo(result, durationLong))
.asMessage()
}
}

private fun afterTestInfo(result: TestResult, duration: TimeSpan?) = mapOf(
private fun afterTestInfo(result: TestResult, duration: Duration) = mapOf(
"type" to "TestEnd",
"status" to "${result.resultType}",
"duration" to "$duration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.zegreatrob.coupling.sdk.CouplingSdkDispatcher
import com.zegreatrob.minassert.assertIsEqualTo
import com.zegreatrob.testmints.action.ActionCannon
import com.zegreatrob.wrapper.wdio.WebdriverBrowser
import korlibs.time.DateTime
import kotlinx.datetime.Clock
import kotlin.test.Test

@Suppress("unused")
Expand All @@ -32,9 +32,7 @@ class HistoryPageE2ETest {
companion object {
private val historyPageSetup = e2eSetup.extend(beforeAll = {
val party = buildParty()
val sdk = sdk.await().apply {
fire(SavePartyCommand(party))
}
val sdk = sdk.await().apply { fire(SavePartyCommand(party)) }

val pairAssignments = setupTwoPairAssignments(party, sdk)

Expand Down Expand Up @@ -73,8 +71,8 @@ class HistoryPageE2ETest {
).onEach { sdk.fire(SavePairAssignmentsCommand(party.id, it)) }

private fun buildPairAssignmentDocument(number: Int, pairs: List<CouplingPair>) = PairAssignmentDocument(
PairAssignmentDocumentId("${DateTime.now().milliseconds}-HistoryPageE2ETest-$number"),
DateTime.now(),
PairAssignmentDocumentId("${Clock.System.now().toEpochMilliseconds()}-HistoryPageE2ETest-$number"),
Clock.System.now(),
pairs.map { it.withPins(emptySet()) },
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import com.zegreatrob.testmints.action.ActionCannon
import com.zegreatrob.wrapper.wdio.WebdriverBrowser
import com.zegreatrob.wrapper.wdio.WebdriverElement
import com.zegreatrob.wrapper.wdio.WebdriverElementArray
import korlibs.time.DateTime
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant
import kotlin.test.Test

@Suppress("unused")
Expand Down Expand Up @@ -170,7 +172,7 @@ class PairAssignmentsPageE2ETest {
private val pairAssignmentDocument by lazy {
PairAssignmentDocument(
id = PairAssignmentDocumentId("${uuid4()}"),
date = DateTime(year = 2015, month = 5, day = 30),
date = LocalDateTime(2015, 5, 30, 0, 0, 0).toInstant(TimeZone.currentSystemDefault()),
pairs = listOf(
pairOf(players[0], players[2]).withPins(emptySet()),
pairOf(players[4]).withPins(emptySet()),
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
com-benasher44-uuid = "com.benasher44:uuid:0.7.1"
com-fasterxml-jackson-core-jackson-databind = "com.fasterxml.jackson.core:jackson-databind:2.15.2"
com-github-ajalt-clikt-clikt = "com.github.ajalt.clikt:clikt:4.1.0"
com-soywiz-korlibs-klock = "com.soywiz.korlibs.klock:klock:4.0.9"
com-zegreatrob-jsmints-jsmints-bom = "com.zegreatrob.jsmints:jsmints-bom:4.3.14"
com-zegreatrob-testmints-testmints-bom = "com.zegreatrob.testmints:testmints-bom:10.1.2"
io-github-microutils-kotlin-logging = "io.github.microutils:kotlin-logging:3.0.5"
Expand Down
1 change: 0 additions & 1 deletion libraries/action/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ dependencies {
commonMainImplementation("org.jetbrains.kotlin:kotlin-stdlib-common")
commonMainImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
commonMainImplementation("com.benasher44:uuid")
commonMainImplementation("com.soywiz.korlibs.klock:klock")
commonMainImplementation("io.github.microutils:kotlin-logging")

commonTestImplementation(project(":libraries:json"))
Expand Down
Loading

0 comments on commit acebbfa

Please sign in to comment.