Skip to content

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

@binkley

Description

@binkley

(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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions