Skip to content

Commit 96ed363

Browse files
committed
feat(apix): timezone wrapper
Differences from the "stable" api common package one: - inline class, no serializer object - constructor null param means "auto" - companion object with `auto` constant and `getTimeZone`s methods
1 parent 17b4fc1 commit 96ed363

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

  • lib/src/main/kotlin/com/openmeteo/apix/common/time
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.openmeteo.apix.common.time
2+
3+
import kotlinx.serialization.Serializable
4+
import java.time.ZoneId
5+
6+
/**
7+
* A [TimeZone] class wrapper
8+
*
9+
* Please note that null is used as an internal value to represent the `"auto"` option
10+
*/
11+
@Serializable
12+
@JvmInline
13+
value class TimeZone private constructor(
14+
val id: String = "auto"
15+
) {
16+
constructor(
17+
timeZone: java.util.TimeZone? = null
18+
) : this(
19+
timeZone?.id ?: "auto"
20+
)
21+
22+
companion object {
23+
val auto = TimeZone("auto")
24+
fun getTimeZone(id: String) =
25+
TimeZone(java.util.TimeZone.getTimeZone(id))
26+
fun getTimeZone(id: ZoneId) =
27+
TimeZone(java.util.TimeZone.getTimeZone(id))
28+
}
29+
30+
val timeZone: java.util.TimeZone?
31+
get() = java.util.TimeZone.getTimeZone(id)
32+
33+
override fun toString(): String = id
34+
}

0 commit comments

Comments
 (0)