From c20508b2f455ff321d2461f830c61eba12aa829d Mon Sep 17 00:00:00 2001 From: Florian Wilhelm <52838694+fwilhe2@users.noreply.github.com> Date: Sun, 27 Dec 2020 09:41:54 +0100 Subject: [PATCH] Remove kotlinx-datetime dependency (#30) This is supposed to make consumption of the library more simple. --- build.gradle | 1 - .../kotlin/com/github/fwilhe/inzell/Inzell.kt | 3 -- src/commonTest/kotlin/SheetsTest.kt | 36 ------------------- 3 files changed, 40 deletions(-) diff --git a/build.gradle b/build.gradle index 58d43d7..6bd0aff 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,6 @@ kotlin { commonMain { dependencies { implementation kotlin('stdlib-common') - implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.1.1") } } diff --git a/src/commonMain/kotlin/com/github/fwilhe/inzell/Inzell.kt b/src/commonMain/kotlin/com/github/fwilhe/inzell/Inzell.kt index ed6a880..52b587d 100644 --- a/src/commonMain/kotlin/com/github/fwilhe/inzell/Inzell.kt +++ b/src/commonMain/kotlin/com/github/fwilhe/inzell/Inzell.kt @@ -1,14 +1,11 @@ package com.github.fwilhe.inzell -import kotlinx.datetime.Instant - typealias columnFunction = (Int) -> Any class Column(val title: String, private val function: columnFunction) { fun eval(i: Int): Any = function.invoke(i) fun evalInt(i: Int): Int = function.invoke(i) as Int fun evalDouble(i: Int): Double = function.invoke(i) as Double - fun evalDate(i: Int): Instant = function.invoke(i) as Instant fun evalString(i: Int): String = function.invoke(i) as String } diff --git a/src/commonTest/kotlin/SheetsTest.kt b/src/commonTest/kotlin/SheetsTest.kt index 78758cf..f46c489 100644 --- a/src/commonTest/kotlin/SheetsTest.kt +++ b/src/commonTest/kotlin/SheetsTest.kt @@ -1,6 +1,5 @@ package com.github.fwilhe.inzell -import kotlinx.datetime.* import kotlin.test.Test import kotlin.test.assertEquals import kotlin.time.Duration @@ -14,41 +13,6 @@ class SheetsTest { assertEquals(expected, sheet) } - @ExperimentalTime - @Test - fun dateCalculations() { - fun f(x: Int): LocalDateTime { - return when (x) { - 1 -> LocalDateTime(2016, 2, 15, 16, 57, 0, 0) - 2 -> LocalDateTime(2017, 4, 15, 16, 7, 0, 0) - 3 -> LocalDateTime(2018, 2, 20, 16, 5, 0, 0) - 4 -> LocalDateTime(2019, 2, 15, 1, 57, 0, 0) - 5 -> LocalDateTime(2020, 2, 15, 16, 5, 0, 0) - 6 -> LocalDateTime(2021, 2, 15, 16, 22, 0, 0) - else -> LocalDateTime(0, 1, 1, 0, 0, 0, 0) - } - } - - fun g(x: Int): Instant { - val now = Clock.System.now() - val instantInThePast: Instant = Instant.parse("2020-01-01T00:00:00Z") - val durationSinceThen: Duration = now - instantInThePast - return f(x).toInstant(TimeZone.UTC) + durationSinceThen - } - - fun h(x: Int): Duration { - return (f(x).toInstant(TimeZone.UTC) - g(x)).absoluteValue - } - - val sheet = spreadsheet { - add(Column("Date", ::f)) - add(Column("Future with added duration", ::g)) - add(Column("Duration between", ::h)) - } - - MarkdownPrinter(sheet).printToStandardOut() - } - @Test fun printTables() { val numberOfCpus = Column("Number of CPUs") { x -> x * x }