Skip to content

Commit a7709c0

Browse files
committed
fix: hardcoded query unix time format
Please note that the `Query.TimeFormat` still exists to let the underlying `toMap` method append the parameter only if the query is a `TimeFormat` one.
1 parent 25e1fd8 commit a7709c0

3 files changed

Lines changed: 11 additions & 30 deletions

File tree

lib/src/main/kotlin/com/openmeteo/api/common/query/Query.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.openmeteo.api.common.query
22

33
import com.openmeteo.api.common.time.Date
4-
import com.openmeteo.api.common.time.TimeFormat.UnixTime
54
import kotlinx.serialization.ExperimentalSerializationApi
65
import kotlinx.serialization.SerialName
76
import kotlinx.serialization.properties.Properties
@@ -21,6 +20,13 @@ interface Query {
2120
inline fun <reified T : Query> toMap(query: T) =
2221
Properties.encodeToStringMap(query)
2322
.filter { (k) -> k != "type" }
23+
.let {
24+
// if resource has timestamps
25+
if (query is TimeFormat)
26+
// always force unix timestamps
27+
it.plus("timeformat" to "unixtime")
28+
else it
29+
}
2430

2531
/**
2632
* Like `.toMap().toList()`
@@ -60,16 +66,10 @@ interface Query {
6066

6167
/**
6268
* Query for resources that have (formatted) time fields.
69+
*
70+
* Used internally to hardcode Unix timestamps.
6371
*/
64-
interface TimeFormat : Query {
65-
/**
66-
* The time format that should be used in the response.
67-
*
68-
* Hardcoded to unix time, since it is easier to parse.
69-
*/
70-
@SerialName("timeformat")
71-
val timeFormat get() = UnixTime
72-
}
72+
interface TimeFormat : Query
7373

7474
/**
7575
* Query for resources that have daily fields.

lib/src/main/kotlin/com/openmeteo/api/common/time/TimeFormat.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/src/main/kotlin/com/openmeteo/api/common/units/Unit.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.openmeteo.api.common.units
22

3-
import com.openmeteo.api.common.time.TimeFormat
43
import kotlinx.serialization.Contextual
54
import kotlinx.serialization.SerialName
65
import kotlinx.serialization.Serializable
@@ -9,7 +8,7 @@ import kotlinx.serialization.Serializable
98
enum class Unit(vararg val alias: @Contextual Any) {
109
Unknown,
1110
@SerialName("unixtime")
12-
UnixTime(TimeFormat.UnixTime),
11+
UnixTime,
1312
@SerialName("")
1413
Dimensionless,
1514
@SerialName("wmo code")

0 commit comments

Comments
 (0)