Extras

valtimer=Timer()timer.schedule(10.seconds){println("This block will be called in 10 seconds")}

The library also includes extensions for Android’s Handler class, this is only available if you compile the “time-android” module.

valhandler=Handler()handler.postDelayed({Log.i("TAG","This will be printed to the Logcat in 2 minutes")},2.minutes)

More extensions will be added to the library in the future.

Conversion safety everywhere

For time-related methods in other third-party libraries in your project, if such methods are frequently used, it’s best to write extention functions that let you use the time units in this libary in those methods. This is mostly just one line of code.

If such methods aren’t frequently used, you can still benefit from the conversion safety that comes with this library.

An example method in a third-party library that does something after a delay period in milliseconds:

classPerson{fundoSomething(delayMillis:Long){// method body
}}

To call the method above with a value of 5 minutes, one would usually write:

valperson=Person()person.doSomething(5*60*1000)

The above line can be written in a safer and clearer way using this library:

Contributing

The goal is for the library to be used wherever possible. If there are extension functions or features you think the library should have, feel free to add them and send a pull request or open an issue. Core Kotlin extensions belong in the “time” module while Android extensions belong in “time-android” module.

Inspiration

The API of Time(Kotlin) has been designed to be as close as possible to Time(Swift) for consistency and because the two languages have many similarities. Check out Time(Swift) if you want a library with the same functionality in Swift.