Skip to content

Commit

Permalink
Add documentation to datetime module
Browse files Browse the repository at this point in the history
  • Loading branch information
janseeger committed Sep 5, 2024
1 parent 0b36eb1 commit 739b4c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 739b4c2

Please sign in to comment.