Skip to content
A Kotlin multi-platform time library.
Kotlin
Branch: master
Clone or download

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Initial Commit Feb 7, 2020
core
gradle/wrapper Initial Commit Feb 7, 2020
.gitignore
LICENSE
README.md
build.gradle Initial Commit Feb 7, 2020
gradle.properties Initial Commit Feb 7, 2020
gradlew
gradlew.bat
settings.gradle Initial Commit Feb 7, 2020

README.md

time

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.

An early look into the development of this library is discussed in this article which was featured in Android Weekly issue #401. Badge

Library

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:

// 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"))
You can’t perform that action at this time.