Skip to content

KomapperCreatedAt and truncate time #927

Answered by nakamura-to
Distractic asked this question in Q&A
Discussion options

You must be logged in to vote

PostgreSQL drivers seem to round up nanoseconds.

You can use ClockProvider.

Create the following class:

import org.komapper.core.ClockProvider
import java.time.Clock
import java.time.Instant
import java.time.ZoneId
import java.time.temporal.ChronoUnit

class MicroClockProvider(private val zoneId: ZoneId = ZoneId.systemDefault()) : ClockProvider {
    override fun now(): Clock {
        val instant = Instant.now().truncatedTo(ChronoUnit.MICROS)
        return Clock.fixed(instant, zoneId)
    }
}

Set an instance of the above class to JdbcDatabase or R2dbcDatabase:

val database = R2dbcDatabase(clockProvider = MicroClockProvider())

See also https://www.komapper.org/docs/reference/database-con…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Distractic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants