diff --git a/sdk/src/main/java/io/radar/sdk/model/RadarAddress.kt b/sdk/src/main/java/io/radar/sdk/model/RadarAddress.kt index 61ae6354..e0481c51 100644 --- a/sdk/src/main/java/io/radar/sdk/model/RadarAddress.kt +++ b/sdk/src/main/java/io/radar/sdk/model/RadarAddress.kt @@ -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?, ) { /** @@ -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? { @@ -200,6 +206,7 @@ class RadarAddress( "fallback" -> RadarAddressConfidence.FALLBACK else -> RadarAddressConfidence.NONE } + val timeZone = RadarTimeZone.fromJson(obj.optJSONObject(FIELD_TIME_ZONE)) return RadarAddress( coordinate, @@ -225,7 +232,8 @@ class RadarAddress( distance, layer, metadata, - confidence + confidence, + timeZone, ) } @@ -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 } diff --git a/sdk/src/main/java/io/radar/sdk/model/RadarTimeZone.kt b/sdk/src/main/java/io/radar/sdk/model/RadarTimeZone.kt new file mode 100644 index 00000000..a2a87da2 --- /dev/null +++ b/sdk/src/main/java/io/radar/sdk/model/RadarTimeZone.kt @@ -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 + } + +}