A Kotlin multi-platform time library.
This library expands on the experimental Kotlin
Duration in the stdlib by providing a
Moment class. This class represents an instance on the timeline which may or may not be localized with a
TimeZoneRegionId and a calculated
TimeOffset from UTC/GMT time.
Note: This library is in the very early stages of development and currently only has implementations for the JVM target.
The entry point to getting a
Moment is through the
TimeProvider interface. There are different implementations depending on the target platform (ex: JVM) and implementation library used (ex: Java Time).
When an instance of the
TimeProvider is created,
Moments can be obtained:
// Moment representing the current time instance timeProvider.now() // Moment for 2,000 days after the epoch timeProvider.moment(durationSinceTheEpoch = 2000.days) // Moment for the start of the current day timeProvider.today() // Moment for the start of the previous day timeProvider.yesterday() // Moment for the start of the next day timeProvider.tomorrow() // Retrieves the static epoch value at UTC/GMT timeProvider.epoch() // Retrieves the current time instance at UTC/GMT timeProvider.utc()
Specific regions can be supplied to get a localized time
// Moment representing the current time instance at the specified region timeProvider.now(TimeZoneRegionId("America/New_York")) // Moment for 2,000 days after the epoch at the specified region timeProvider.moment(durationSinceTheEpoch = 2000.days, regionId = TimeZoneRegionId("America/New_York"))