I'm trying to transition my code to use kotlinx.datetime instead of the java.time library as I'd like to make use of the serialization benefits of the kotlinx library (it can serialize instant using the @Serialize annotation).
However, i have tests that are using the java.time.Clock and while there is a kotlinx.datetime.Clock class, it appears much more limited than the java one.
Is there a way I can achieve the same thing as this (which uses java.time.Clock and java.time.Instant):
val clockFixed = Clock.fixed(Instant.now().minusMillis(1000), ZONE_ID_UTC)
using the kotlinx library? It doesn't have to be exactly like for like but I would like a clock that always returns the same instant so I can use it for tests and for production code.
kotlinx.datetime.Clockis a very simple interface that (as of version0.4.0) only includes a single function declaration.As of
0.4.0there is no implementation of aFixedclock provided by the library itself. However, you can easily provide your own implementation of aFixedclock and make it available on thecompanion objectof theClockinterface.Then, you can use it like the official
Systemclock provided by the library.