I’m currently facing a problem in Android Studio.
I’ve been trying to subtract two Time Mark, but I get the following error:
“Using ‘minus(TimeMark): Duration’ is an error. Subtracting one TimeMark from another is not a well defined operation because these time marks could have been obtained from the different time sources.“
I’ve simplified my code to understand what was wrong, searched on Google and Bing but there was no mention of a similar problem.
Here the code
@OptIn(ExperimentalTime::class)
val timeSource = TimeSource.Monotonic
val startTime = timeSource.markNow()
processing()
val endTime = timeSource.markNow()
val duration : Duration = endTime-startTime
Could you help me with this matter? Your help would be very much appreciated!
I’ve checked the current version of Kotlin and it’s the version 1.9.0 so it was supposed to work.
I’ve already imported the library linked to all the time functions import kotlin.time.*