Skip to content

Commit

Permalink
Remove kotlinx-datetime dependency (#30)
Browse files Browse the repository at this point in the history
This is supposed to make consumption of the library more simple.
  • Loading branch information
fwilhe2 authored Dec 27, 2020
1 parent ad85afb commit c20508b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 40 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ kotlin {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.1.1")
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/commonMain/kotlin/com/github/fwilhe/inzell/Inzell.kt
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
36 changes: 0 additions & 36 deletions src/commonTest/kotlin/SheetsTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.fwilhe.inzell

import kotlinx.datetime.*
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.time.Duration
Expand All @@ -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 }
Expand Down

0 comments on commit c20508b

Please sign in to comment.