article banner

Exercise: Multiplatform LocalDateTime

In your multiplatform project, you need to define a common type to represent time. You decided that you want it to behave just like LocalDateTime from the java.time library. In fact, you decided that on Kotlin/JVM you want to use LocalDateTime directly as an actual type. Define a common type LocalDateTime; then, define an actual typealias for Kotlin/JVM and an actual class for Kotlin/JS that wraps over Date from JavaScript.

These are the expected elements that you need to provide for each platform:

expect class LocalDateTime { fun getSecond(): Int fun getMinute(): Int fun getHour(): Int fun plusSeconds(seconds: Long): LocalDateTime } expect fun now(): LocalDateTime expect fun parseLocalDateTime(str: String): LocalDateTime

Starting code and unit tests for this exercise can be found in the project:

Once you are done with the exercise, you can check your solution here.