diff --git a/dachlatten-datetime/src/main/kotlin/de/sipgate/dachlatten/datetime/DateExt.kt b/dachlatten-datetime/src/main/kotlin/de/sipgate/dachlatten/datetime/DateExt.kt index 577ebff..bef4866 100644 --- a/dachlatten-datetime/src/main/kotlin/de/sipgate/dachlatten/datetime/DateExt.kt +++ b/dachlatten-datetime/src/main/kotlin/de/sipgate/dachlatten/datetime/DateExt.kt @@ -6,5 +6,8 @@ import java.time.LocalDateTime import java.util.Date import java.util.TimeZone +/** + * Convenience converter from Java Date to the new DateTime API + */ @RequiresApi(Build.VERSION_CODES.O) fun Date.toLocalDateTime(zone: TimeZone): LocalDateTime = LocalDateTime.ofInstant(toInstant(), zone.toZoneId()) diff --git a/dachlatten-datetime/src/main/kotlin/de/sipgate/dachlatten/datetime/FixedClock.kt b/dachlatten-datetime/src/main/kotlin/de/sipgate/dachlatten/datetime/FixedClock.kt index 2983640..24ff119 100644 --- a/dachlatten-datetime/src/main/kotlin/de/sipgate/dachlatten/datetime/FixedClock.kt +++ b/dachlatten-datetime/src/main/kotlin/de/sipgate/dachlatten/datetime/FixedClock.kt @@ -3,6 +3,12 @@ package de.sipgate.dachlatten.datetime import kotlinx.datetime.Clock import kotlinx.datetime.Instant +/** + * Helper function to provide Clock instances providing fixed Instants + * + * This is useful for unit tests to inject Clocks that will always return a known value for `now()`. + */ +@Suppress("FunctionName") fun Clock.Companion.Fixed(instant: Instant) = object : Clock { override fun now(): Instant = instant }