https://github.com/sandjelkovic/kxjtime
Kotlin extension library wrapping java.time API
https://github.com/sandjelkovic/kxjtime
date-time duration extensions kotlin time utilities utils
Last synced: 14 days ago
JSON representation
Kotlin extension library wrapping java.time API
- Host: GitHub
- URL: https://github.com/sandjelkovic/kxjtime
- Owner: sandjelkovic
- License: apache-2.0
- Created: 2018-06-14T08:55:54.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-11-08T10:15:17.000Z (over 3 years ago)
- Last Synced: 2025-03-26T06:43:34.784Z (about 1 month ago)
- Topics: date-time, duration, extensions, kotlin, time, utilities, utils
- Language: Kotlin
- Homepage: https://www.sandjelkovic.com/kxjtime/kxjtime/
- Size: 94.7 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://maven-badges.herokuapp.com/maven-central/com.sandjelkovic.kxjtime/kxjtime/)
[](https://gitlab.com/sandjelkovic/kxjtime/commits/develop)
[](https://travis-ci.com/sandjelkovic/kxjtime)# KxjTime
KxjTime is a micro library that provides a convenient way to create [java.time API](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html) objects.## Usage
Simplify creation of various objects from `java.time` API.
#### Extensions for Integers and Longs
Create [Duration](https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html) from Integers
```kotlin
val thirtyMinutes = 30.minutes
val twoMilliseconds = 2.milliseconds
```
Which can be then combined by Kotlin overloaded operators or with infix `and`
```kotlin
val duration1 = 10.days + 1.hours + 5.minutes + 3.seconds
val duration2 = 10.days and 1.hours and 5.minutes and 3.seconds
```
#### Natural language
Combine [Duration](https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html) with Time-based classes
```kotlin
val createdAt = 10.days and 1.hours and 5.minutes before ZonedDateTime.now()
val willDoSomethingAt = 30.minutes + 10.seconds + 3.hours after Instant.now()
```
Readable and concise code
```kotlin
if (createdAt.isBefore(30.minutes + 10.seconds + 3.hours after now)) {
// do something
}
if (now.isAfter(12.hours after scheduledTime)) {
// do something later
}
```## Deprecation note
With the recent releases of Kotlin time library this library is not needed anymore if you use newer Kotlin versions