Skip to content

Commit

Permalink
fix: hardcoded query unix time format
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DadiBit committed Jun 4, 2023
1 parent 25e1fd8 commit a7709c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 30 deletions.
20 changes: 10 additions & 10 deletions lib/src/main/kotlin/com/openmeteo/api/common/query/Query.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.openmeteo.api.common.query

import com.openmeteo.api.common.time.Date
import com.openmeteo.api.common.time.TimeFormat.UnixTime
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.properties.Properties
Expand All @@ -21,6 +20,13 @@ interface Query {
inline fun <reified T : Query> toMap(query: T) =
Properties.encodeToStringMap(query)
.filter { (k) -> k != "type" }
.let {
// if resource has timestamps
if (query is TimeFormat)
// always force unix timestamps
it.plus("timeformat" to "unixtime")
else it
}

/**
* Like `.toMap().toList()`
Expand Down Expand Up @@ -60,16 +66,10 @@ interface Query {

/**
* Query for resources that have (formatted) time fields.
*
* Used internally to hardcode Unix timestamps.
*/
interface TimeFormat : Query {
/**
* The time format that should be used in the response.
*
* Hardcoded to unix time, since it is easier to parse.
*/
@SerialName("timeformat")
val timeFormat get() = UnixTime
}
interface TimeFormat : Query

/**
* Query for resources that have daily fields.
Expand Down
18 changes: 0 additions & 18 deletions lib/src/main/kotlin/com/openmeteo/api/common/time/TimeFormat.kt

This file was deleted.

3 changes: 1 addition & 2 deletions lib/src/main/kotlin/com/openmeteo/api/common/units/Unit.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.openmeteo.api.common.units

import com.openmeteo.api.common.time.TimeFormat
import kotlinx.serialization.Contextual
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand All @@ -9,7 +8,7 @@ import kotlinx.serialization.Serializable
enum class Unit(vararg val alias: @Contextual Any) {
Unknown,
@SerialName("unixtime")
UnixTime(TimeFormat.UnixTime),
UnixTime,
@SerialName("")
Dimensionless,
@SerialName("wmo code")
Expand Down

0 comments on commit a7709c0

Please sign in to comment.