kotlinx-datetime icon indicating copy to clipboard operation
kotlinx-datetime copied to clipboard

Shims (extension functions) to better match JDK's API

Open binkley opened this issue 4 years ago • 1 comments

(If this is a duplicate issue, apologies. I didn't spot it.)

To aid in migration from JDK's datetime API to kotlinx-datetime, shims would be helpful. An example:

/** Shim for compatibility with JDK's `Instant` */
public fun Instant.minusSeconds(seconds: Long): Instant =
    this - Duration.seconds(seconds)

This example gives the same API call for kotlinx-datetime Instant as for JDK's Instant class. I stumbled on this while migrating a project from JDK's API to kotlinx-datetime. These kind of shims are helpful to encourage migration, and make it more painless. An ideal situation would be just:

  1. Update the build dependencies
  2. Update the import statements in Kotlin source files

Were the shims in a separate dependency, that would be just as simple (only step # 1 changes) if that were better aligned with project goals.

binkley avatar Aug 11 '21 00:08 binkley

@binkley Idk if you're still interested in this but check this library I made to address the missing extension functions in the original library here -> https://github.com/RaedGhazal/kotlinx-datetime-ext

** let me know if sharing links isn't allowed here

RaedGhazal avatar Mar 26 '24 21:03 RaedGhazal