All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hnau.base.extensions.time.TimeTimezoneExtensions.kt Maven / Gradle / Ivy

There is a newer version: 2.1.9
Show newest version
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