Skip to content

Commit 275d568

Browse files
committed
Add support for OffsetDateTime and fix tests.
1 parent 74a08cb commit 275d568

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

plot-api/src/commonTest/kotlin/org/jetbrains/letsPlot/intern/standardizing/StandardizingTest.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class StandardizingTest {
5757
val kLocalTime = KLocalTime(12, 30, 45)
5858
val kLocalDateTime = KLocalDateTime(2023, 1, 1, 12, 30, 45)
5959

60-
val values = listOf(
60+
val values = listOf<Any>(
6161
kInstant,
6262
kLocalDate,
6363
kLocalTime,
@@ -66,16 +66,17 @@ class StandardizingTest {
6666

6767
val expectedValues = values.map {
6868
when (it) {
69-
is KLocalDate -> expectedLocalDateTimestamp.toDouble() // Same as ZonedDateTime because here we use UTC
70-
is KLocalTime -> expectedLocalTimeTimestamp.toDouble() // Same as ZonedDateTime because here we use UTC
71-
is KLocalDateTime -> expectedTimestamp.toDouble() // Same as ZonedDateTime because here we use UTC
72-
else -> expectedTimestamp.toDouble()
73-
}
69+
is KLocalDate -> expectedLocalDateTimestamp
70+
is KLocalTime -> expectedLocalTimeTimestamp
71+
is KLocalDateTime -> expectedTimestamp // Same as ZonedDateTime because here we use UTC
72+
else -> expectedTimestamp
73+
}.toDouble()
7474
} + StandardizingTestJvmValues.getExpectedValues()
7575

7676

77-
val standardizedValues = SeriesStandardizing.toList(values + StandardizingTestJvmValues.getTestValues())
78-
values.zip(expectedValues).zip(standardizedValues) { (a, b), c ->
77+
val inputValues = values + StandardizingTestJvmValues.getTestValues()
78+
val standardizedValues = SeriesStandardizing.toList(inputValues)
79+
inputValues.zip(expectedValues).zip(standardizedValues) { (a, b), c ->
7980
Triple(a, b, c)
8081
}
8182
.forEach { (input, expected, result) ->
@@ -149,4 +150,5 @@ class StandardizingTest {
149150
}
150151
}
151152

153+
@Suppress("unused")
152154
private enum class State { Idle, Working }

plot-api/src/commonTest/kotlin/org/jetbrains/letsPlot/intern/standardizing/StandardizingTestJvmValues.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package org.jetbrains.letsPlot.intern.standardizing
77

88
expect object StandardizingTestJvmValues {
9-
fun getTestValues(): List<Any?>
10-
fun getExpectedValues(): List<Any?>
11-
9+
fun getTestValues(): List<Any>
10+
fun getExpectedValues(): List<Any>
1211
}

plot-api/src/jsTest/kotlin/org/jetbrains/letsPlot/intern/standardizing/StandardizingTestJvmValues.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package org.jetbrains.letsPlot.intern.standardizing
77

88
actual object StandardizingTestJvmValues {
9-
actual fun getTestValues(): List<Any?> = emptyList()
10-
actual fun getExpectedValues(): List<Any?> = emptyList()
11-
9+
actual fun getTestValues(): List<Any> = emptyList()
10+
actual fun getExpectedValues(): List<Any> = emptyList()
1211
}

plot-api/src/jvmMain/kotlin/org/jetbrains/letsPlot/intern/standardizing/JvmStandardizing.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ actual object JvmStandardizing {
2121
is Date -> true
2222
is Instant -> true
2323
is ZonedDateTime -> true
24+
is OffsetDateTime -> true
2425
is LocalDate -> true
2526
is LocalTime -> true
2627
is LocalDateTime -> true
@@ -47,6 +48,7 @@ actual object JvmStandardizing {
4748
is Date -> o.time.toDouble()
4849
is Instant -> o.toEpochMilli().toDouble()
4950
is ZonedDateTime -> o.toInstant().toEpochMilli().toDouble()
51+
is OffsetDateTime -> o.toInstant().toEpochMilli().toDouble()
5052
is LocalDate -> o.atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli().toDouble()
5153
is LocalTime -> LocalDateTime.of(LocalDate.EPOCH, o).toInstant(ZoneOffset.UTC).toEpochMilli().toDouble()
5254
is LocalDateTime -> o.toInstant(ZoneOffset.UTC).toEpochMilli().toDouble()

plot-api/src/jvmTest/kotlin/org/jetbrains/letsPlot/intern/standardizing/StandardizingTestJvmValues.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import java.time.*
99
import java.util.*
1010

1111
actual object StandardizingTestJvmValues {
12-
actual fun getTestValues(): List<Any?> {
12+
actual fun getTestValues(): List<Any> {
1313
val zonedDateTime = ZonedDateTime.of(2023, 1, 1, 12, 30, 45, 0, ZoneId.of("UTC"))
1414
val instant = zonedDateTime.toInstant()
1515
val localDate = zonedDateTime.toLocalDate()
1616
val localTime = zonedDateTime.toLocalTime()
1717
val localDateTime = zonedDateTime.toLocalDateTime()
1818
val date = Date.from(instant)
19+
val offsetDateTime: OffsetDateTime = zonedDateTime.toOffsetDateTime()
1920

2021
return listOf(
2122
zonedDateTime,
@@ -24,10 +25,11 @@ actual object StandardizingTestJvmValues {
2425
localTime,
2526
localDateTime,
2627
date,
28+
offsetDateTime,
2729
)
2830
}
2931

30-
actual fun getExpectedValues(): List<Any?> {
32+
actual fun getExpectedValues(): List<Any> {
3133
// Expected timestamp for 2023-01-01T12:30:45Z
3234
val expectedTimestamp = 1672576245000L
3335

@@ -43,7 +45,7 @@ actual object StandardizingTestJvmValues {
4345
is LocalTime -> expectedLocalTimeTimestamp
4446
is LocalDateTime -> expectedTimestamp // Same as ZonedDateTime because here we use UTC
4547
else -> expectedTimestamp
46-
}
48+
}.toDouble()
4749
}
4850
}
4951
}

0 commit comments

Comments
 (0)