fluid-time
Additions for Kotlin's date & time library kotlinx-datetime
.
kotlinx-datetime
is very early stage and not as actively developed as other official libraries. This library keeps adding missing pieces until the official library catches up.
Installation
build.gradle.kts
:
dependencies {
implementation("io.fluidsonic.time:fluid-time:0.14.0")
}
Additions
Duration(days, hours, minutes, seconds, nanoseconds)
–Duration
factory function using componentsDuration.parse()/.parseOrNull()
- parseDuration
from ISO-8601 stringDurationSerializer
-kotlinx-serialization
serializer forDuration
LocalDate.atTime(LocalTime): LocalDateTime
- createLocalDateTime
fromLocalDate
andLocalTime
LocalDateOrNull(year, month, day)
- likeLocalDate()
but returnsnull
instead of throwingLocalDateTime.time
- returns its time components asLocalTime
LocalTime
- similar to the existingLocalDate
andLocalDateTime
LocalTime.midnight
-00:00
LocalTime.atDate(LocalDate): LocalDateTime
- createLocalDateTime
fromLocalDate
andLocalTime
Timestamp
- alias ofInstant
for those who prefer that name (Discussion)(LocalDate|LocalDateTime|LocalTime|Timestamp).parseOrNull(String)
- likeparse()
but returnsnull
instead of throwingTimeZone.ofOrNull(String)
- likeof()
but returnsnull
instead of throwingTimestamp.durationSince(Timestamp)/.durationUntil(Timestamp)
- getDuration
between two timestampsTimestamp.toLocalDate(TimeZone)
- shortcut for.toLocalDateTime(timeZone).date
Timestamp.toLocalTime(TimeZone)
- shortcut for.toLocalDateTime(timeZone).time
Timestamp.toJavaDate(): Date
- converts aTimestamp
tojava.util.Date
(JVM only)Month.daysIn(year)
- number of days in a given month and yearYear.isLeap(year)
- whether a year is a leap yearManualClock
- aClock
implementation suitable for unit testing- JVM, JS and Darwin are supported.
linuxX64
andmingwX64
are not supported.
Previous library
Before kotlinx-datetime
was released this library has provided its own date & time implementations for JVM and Darwin. That work has been discontinued in favor of using the new official library, even if experimental, with additions provided by this reworked library. Bugfix releases will still be provided if needed.
You can still use the last previous library version 0.10.5.
License
Apache 2.0