If it was a library that I was open sourcing, I mi...
# kotest
s
If it was a library that I was open sourcing, I might do the longer example I pasted up because it stops people using the Time constructor and accidentally creating Time's with > 59 seconds. If it was something only I was using, I would probably go the shorter route and add the normalizing function and use that, as I would know not to call the constructor. Or thirdly, you could just normalize everything into seconds, and then extract minutes etc as functions on top of a Time class.
Copy code
data class Time(val totalSeconds: Int) {
   constructor(minutes: Int, seconds: Int) : this(minutes * 60 + seconds)
   constructor(hours: Int, minutes: Int, seconds: Int) : this(hours * 60 * 60 + minutes * 60 + seconds)
}

val Time.seconds get() = ...
val Time.minutes get() = ...
val Time.hours get() = ...