Skip to content

Commit

Permalink
Shicheng/fence 1984 timezone payload in geocoding responses in sdks 2 (
Browse files Browse the repository at this point in the history
…#375)

* add radar time zone class

* add radar time zone to address
  • Loading branch information
ShiCheng-Lu authored Jul 24, 2024
1 parent 8085041 commit b982c93
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sdk/src/main/java/io/radar/sdk/model/RadarAddress.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ class RadarAddress(
/**
* The confidence level of the geocoding result.
*/
val confidence: RadarAddressConfidence
val confidence: RadarAddressConfidence,

/**
* The time zone information of the location.
*/
val timeZone: RadarTimeZone?,
) {

/**
Expand Down Expand Up @@ -164,6 +169,7 @@ class RadarAddress(
private const val FIELD_LAYER = "layer"
private const val FIELD_METADATA = "metadata"
private const val FIELD_CONFIDENCE = "confidence"
private const val FIELD_TIME_ZONE = "timeZone"

@JvmStatic
fun fromJson(obj: JSONObject?): RadarAddress? {
Expand Down Expand Up @@ -200,6 +206,7 @@ class RadarAddress(
"fallback" -> RadarAddressConfidence.FALLBACK
else -> RadarAddressConfidence.NONE
}
val timeZone = RadarTimeZone.fromJson(obj.optJSONObject(FIELD_TIME_ZONE))

return RadarAddress(
coordinate,
Expand All @@ -225,7 +232,8 @@ class RadarAddress(
distance,
layer,
metadata,
confidence
confidence,
timeZone,
)
}

Expand Down Expand Up @@ -300,6 +308,7 @@ class RadarAddress(
obj.putOpt(FIELD_LAYER, this.layer)
obj.putOpt(FIELD_METADATA, this.metadata)
obj.putOpt(FIELD_CONFIDENCE, stringForConfidence(this.confidence))
obj.putOpt(FIELD_TIME_ZONE, this.timeZone?.toJson())
return obj
}

Expand Down
82 changes: 82 additions & 0 deletions sdk/src/main/java/io/radar/sdk/model/RadarTimeZone.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package io.radar.sdk.model

import org.json.JSONArray
import org.json.JSONObject

/**
* Represents a time zone.
*/
class RadarTimeZone(
/**
*
*/
val id: String,

/**
*
*/
val name: String,

/**
*
*/
val code: String,

/**
*
*/
val currentTime: String,

/**
*
*/
val utcOffset: Int,

/**
*
*/
val dstOffset: Int,
) {
internal companion object {
private const val FIELD_ID = "id"
private const val FIELD_NAME = "name"
private const val FIELD_CODE = "code"
private const val FIELD_CURRENT_TIME = "currentTime"
private const val FIELD_UTC_OFFSET = "utcOffset"
private const val FIELD_DST_OFFSET = "dstOffset"

@JvmStatic
fun fromJson(obj: JSONObject?): RadarTimeZone? {
if (obj == null) {
return null
}
val id = obj.getString("id")
val name = obj.getString("name")
val code = obj.getString("code")
val currentTime = obj.getString("currentTime")
val utcOffset = obj.getInt("utcOffset")
val dstOffset = obj.getInt("dstOffset")

return RadarTimeZone(
id,
name,
code,
currentTime,
utcOffset,
dstOffset,
)
}
}

fun toJson(): JSONObject {
val obj = JSONObject()
obj.putOpt(FIELD_ID, id)
obj.putOpt(FIELD_NAME, name)
obj.putOpt(FIELD_CODE, code)
obj.putOpt(FIELD_CURRENT_TIME, currentTime)
obj.putOpt(FIELD_UTC_OFFSET, utcOffset)
obj.putOpt(FIELD_DST_OFFSET, dstOffset)
return obj
}

}

0 comments on commit b982c93

Please sign in to comment.