org.hnau.base.extensions.time.TimeTimezoneExtensions.kt Maven / Gradle / Ivy
package org.hnau.base.extensions.time
import org.hnau.base.data.Time
import java.util.*
val timeZoneUTC: TimeZone = TimeZone.getTimeZone("UTC")
val TimeZone.offset: Time
get() = this.rawOffset.asMilliseconds
fun Time.changeTimeZone(
fromTimeZone: TimeZone,
toTimeZone: TimeZone
) = this - fromTimeZone.offset + toTimeZone.offset
fun Time.toUTC(
fromTimeZone: TimeZone = TimeZone.getDefault()
) = changeTimeZone(
fromTimeZone = fromTimeZone,
toTimeZone = timeZoneUTC
)
fun Time.fromUTC(
toTimeZone: TimeZone = TimeZone.getDefault()
) = changeTimeZone(
fromTimeZone = timeZoneUTC,
toTimeZone = toTimeZone
)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy