Package-level declarations

Types

Link copied to clipboard
class ComputedTime(val weeks: Int = 0, val days: Int = 0, val hours: Int = 0, val minutes: Int = 0, val seconds: Int = 0, val nanoseconds: Int = 0)
Link copied to clipboard
value class Date(val encoded: Int) : Comparable<Date> , Serializable

Represents a triple of year, month and day.

Link copied to clipboard
data class DateComponents(val mode: DateComponents.Mode = Mode.DATE, val years: Int = 0, val months: Int = 0, val days: Int = 0, val hours: Int = 0, val minutes: Int = 0, val seconds: Int = 0, val nanoseconds: Int = 0, val offset: Duration? = null, val sign: Int = +1, val isTime: Boolean = false)
Link copied to clipboard
Link copied to clipboard

An exception for Date operations.

Link copied to clipboard

Allows to format and parse instances of Date, DateTime and DateTimeTz

Link copied to clipboard
value class DateTime(val unixMillis: Double) : Comparable<DateTime> , Serializable

Represents a Date in UTC (GMT+00) with millisecond precision.

Link copied to clipboard
data class DateTimeRange(val from: DateTime, val to: DateTime) : Comparable<DateTime> , Serializable

Represents a right-opened range between two dates.

Link copied to clipboard
Link copied to clipboard
data class DateTimeSpan(val monthSpan: MonthSpan, val duration: Duration) : Comparable<DateTimeSpan> , Serializable

Immutable structure representing a set of a monthSpan and a duration. This structure loses information about which months are included, that makes it impossible to generate a real Duration including months. You can use DateTimeRange.duration to get this information from two real DateTime.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Represents the day of the week. Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday.

Link copied to clipboard
data class DayOfWeekWithLocale(val dayOfWeek: DayOfWeek, val locale: KlockLocale) : Comparable<DayOfWeekWithLocale>
Link copied to clipboard

Analogous to Duration but doesn't allocate on the JS target. Important when used intensively in JS code. For example in KorGE.

Link copied to clipboard
data class FastTimedValue<T>(val value: T, val duration: FastDuration)
Link copied to clipboard
Link copied to clipboard
class IntTimedCache(val ttl: Duration, val timeProvider: TimeProvider = TimeProvider, val gen: () -> Int)
Link copied to clipboard
Link copied to clipboard
class ISODateComponentsFormat(val format: String, val twoDigitBaseYear: Int = 1900) : DateComponentsFormat
Link copied to clipboard
open class ISODateComponentsFormatEx(val basicFormat: String?, val extendedFormat: String?) : DateComponentsFormat
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
abstract class KlockLocale
Link copied to clipboard
data class KlockLocaleContext(val gender: KlockLocaleGender = KlockLocaleGender.Neuter)
Link copied to clipboard
Link copied to clipboard

Represents one of the twelve months of the year.

Link copied to clipboard
value class MonthSpan(val totalMonths: Int) : Comparable<MonthSpan> , Serializable

Represents a number of years and months temporal distance.

Link copied to clipboard
value class NumberOfTimes(val count: Int)
Link copied to clipboard
data class PatternDateComponentsFormat(val format: String, val locale: KlockLocale? = null, val tzNames: TimezoneNames = TimezoneNames.DEFAULT) : DateComponentsFormat
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Class for measuring relative times with as much precision as possible.

Link copied to clipboard
class Stopwatch(val nanosecondProvider: () -> Double = { PerformanceCounter.nanoseconds })
Link copied to clipboard
value class Time(val encoded: Duration) : Comparable<Time> , Serializable

Represents a union of millisecond, second, minute and hour.

Link copied to clipboard
class TimedCache<T : Any>(var ttl: Duration, val timeProvider: TimeProvider = TimeProvider, val gen: () -> T)
Link copied to clipboard
typealias TimedResult<T> = TimedValue<T>
Link copied to clipboard
Link copied to clipboard
interface TimeProvider

Class to provide time that can be overridden to mock or change its behaviour.

Link copied to clipboard
class TimeSampler(var timeWindow: Duration = 1.seconds)

Class to count the number of times a sample was added in a timeWindow

Link copied to clipboard
typealias TimeSpan = Duration

Represents a span of time, with milliseconds precision.

Link copied to clipboard
Link copied to clipboard
data class TimezoneNames(val timeZones: List<Timezone>) : Serializable
Link copied to clipboard
value class TimezoneOffset(val totalMilliseconds: Double) : Comparable<TimezoneOffset> , Serializable

Represents a time zone offset with millisecond precision. Usually minute is enough. Can be used along DateTimeTz to construct non universal, local times.

Link copied to clipboard
value class Year(val year: Int) : Comparable<Year> , Serializable

Represents a Year in a typed way.

Link copied to clipboard
value class YearMonth(internalPackedInfo: Int) : Serializable

Represents a couple of year and month.

Properties

Link copied to clipboard
Link copied to clipboard

Returns a DateTime of this day with the hour at 23:59:59.999

Link copied to clipboard

Returns a DateTime of this day with the hour at 00:00:00

Link copied to clipboard
Link copied to clipboard

Duration representing this number as days or 86_400 seconds.

Returns the total number of days for this Duration (86_400 seconds)

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Duration representing this number as hours or 3_600 seconds.

Returns the total number of hours for this Duration (3_600 seconds)

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Return true if Duration.NIL

Link copied to clipboard

Returns this date with the local offset of this device. Components might change because of the offset.

Link copied to clipboard

The local offset for this date for the timezone of the device

Link copied to clipboard

Returns a new local date that will match these components.

Link copied to clipboard

Duration representing this number as microseconds or 1 / 1_000_000 seconds.

Returns the total number of microseconds for this Duration (1 / 1_000_000 seconds)

Link copied to clipboard

Returns the total number of microseconds for this Duration (1 / 1_000_000 seconds) as Integer

Link copied to clipboard

Returns the total number of milliseconds as an Int

Link copied to clipboard

Returns the total number of milliseconds as a Long

Link copied to clipboard

Duration representing this number as minutes or 60 seconds.

Returns the total number of minutes for this Duration (60 seconds)

Link copied to clipboard

The Month part

Link copied to clipboard

Months part of this MonthSpan as integer

Creates a MonthSpan representing these months.

Link copied to clipboard

Duration representing this number as nanoseconds or 1 / 1_000_000_000 seconds.

Returns the total number of nanoseconds for this Duration (1 / 1_000_000_000 seconds)

Link copied to clipboard

Returns the total number of nanoseconds for this Duration (1 / 1_000_000_000 seconds) as Integer

Link copied to clipboard

Returns the total number of nanoseconds for this Duration (1 / 1_000_000_000 seconds)

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Duration representing this number as seconds.

Returns the total number of seconds for this Duration

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Total years of this MonthSpan as double (might contain decimals)

Link copied to clipboard

Returns this date with a 0 offset. Components are equal.

Link copied to clipboard

Duration representing this number as weeks or 604_800 seconds.

Returns the total number of weeks for this Duration (604_800 seconds)

Link copied to clipboard

The Year part

Link copied to clipboard

Represents a couple of Year and Month that has leap information and thus allows to get the number of days of that month

Link copied to clipboard

Years part of this MonthSpan as integer

Creates a MonthSpan representing these years.

Functions

Link copied to clipboard
fun DateTime.add(dateSpan: MonthSpan, duration: Duration): DateTime

Constructs a new DateTime after adding dateSpan and duration

fun DateTime.add(deltaMonths: Int, deltaMilliseconds: Double): DateTime

Constructs a new DateTime after adding deltaMonths and deltaMilliseconds

Link copied to clipboard

Sleeps the thread during the specified time. Spinlocks on JS

Link copied to clipboard
Link copied to clipboard
inline fun Duration.coalesce(block: () -> Duration): Duration
Link copied to clipboard
operator fun Duration.compareTo(other: FastDuration): Int
Link copied to clipboard
fun DateTime.convertRange(srcMin: DateTime, srcMax: DateTime, dstMin: DateTime, dstMax: DateTime): DateTime
fun Duration.convertRange(srcMin: Duration, srcMax: Duration, dstMin: Duration, dstMax: Duration): Duration
Link copied to clipboard
fun DateTime.copyDayOfMonth(year: Year = this.year, month: Month = this.month, dayOfMonth: Int = this.dayOfMonth, hours: Int = this.hours, minutes: Int = this.minutes, seconds: Int = this.seconds, milliseconds: Int = this.milliseconds): DateTime
Link copied to clipboard
operator fun Duration.div(other: FastDuration): Double
inline operator fun Duration.div(scale: Float): Duration
Link copied to clipboard
infix inline fun Duration.divFloat(other: Duration): Float
Link copied to clipboard
Link copied to clipboard
inline fun fastMeasureTime(block: () -> Unit): FastDuration

Executes a callback and measure the time it takes to complete.

inline fun <T> fastMeasureTime(callback: () -> T, handleTime: (FastDuration) -> Unit): T
Link copied to clipboard
inline fun <T> fastMeasureTimedValue(callback: () -> T): FastTimedValue<T>
Link copied to clipboard
fun Year.first(dayOfWeek: DayOfWeek): DateTime
Link copied to clipboard
fun Year.firstDate(dayOfWeek: DayOfWeek): Date
Link copied to clipboard
fun DateTime.format(format: String, locale: KlockLocale): String
fun DateTimeTz.format(format: String, locale: KlockLocale): String

Converts this date to String using format for representing it

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Constructs a new DateTime by parsing the str using standard date formats.

Link copied to clipboard
Link copied to clipboard
fun Date.inThisWeek(dayOfWeek: DayOfWeek, locale: KlockLocale = KlockLocale.default): Date
Link copied to clipboard
operator fun DateTime.Companion.invoke(date: Date, time: Time = Time(0.milliseconds)): DateTime
operator fun DateTime.Companion.invoke(year: Year, month: Month, day: Int, hour: Int = 0, minute: Int = 0, second: Int = 0, milliseconds: Int = 0): DateTime
operator fun DateTime.Companion.invoke(year: Int, month: Month, day: Int, hour: Int = 0, minute: Int = 0, second: Int = 0, milliseconds: Int = 0): DateTime

Constructs a new DateTime from date and time information.

Link copied to clipboard
Link copied to clipboard
inline fun TimeProvider.measure(block: () -> Unit): Duration
Link copied to clipboard
inline fun TimeProvider.measureFast(block: () -> Unit): FastDuration
Link copied to clipboard
inline fun <T> measureTime(callback: () -> T, handleTime: (Duration) -> Unit): T
Link copied to clipboard
inline fun <T> measureTimeWithResult(callback: () -> T): TimedValue<T>

Executes the callback measuring the time it takes to complete. Returns a TimedResult with the time and the return value of the callback.

Link copied to clipboard
Link copied to clipboard
operator fun Date.minus(time: DateTimeSpan): Date
operator fun Date.minus(time: MonthSpan): Date
operator fun Date.minus(time: Time): DateTime
operator fun Date.minus(time: Duration): Date
operator fun DateTime.minus(delta: DateTimeSpan): DateTime
operator fun DateTime.minus(delta: MonthSpan): DateTime
operator fun Duration.minus(other: DateTimeSpan): DateTimeSpan
operator fun Duration.minus(other: FastDuration): FastDuration
operator fun Duration.minus(other: MonthSpan): DateTimeSpan
Link copied to clipboard
Link copied to clipboard

Returns the current local time as DateTimeTz.

Link copied to clipboard

Constructs a new DateTime by parsing the str using standard date formats.

fun DateFormat.parse(str: String, doAdjust: Boolean = true): DateTimeTz
fun TimeFormat.parse(str: String, doAdjust: Boolean = true): Duration
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
operator fun Date.plus(time: DateTimeSpan): Date
operator fun Date.plus(time: MonthSpan): Date
operator fun Date.plus(time: Time): DateTime
operator fun Date.plus(time: Duration): Date
operator fun DateTime.plus(delta: DateTimeSpan): DateTime
operator fun DateTime.plus(delta: MonthSpan): DateTime
operator fun Time.plus(span: Duration): Time
operator fun Duration.plus(other: DateTimeSpan): DateTimeSpan
operator fun Duration.plus(other: FastDuration): FastDuration
operator fun Duration.plus(other: MonthSpan): DateTimeSpan
Link copied to clipboard
inline operator fun Duration.rem(other: Duration): Duration
Link copied to clipboard
Link copied to clipboard
operator fun Duration.times(other: FastDuration): FastDuration
inline operator fun Duration.times(scale: Float): Duration
Link copied to clipboard
inline fun TimeSpan(milliseconds: Double): Duration
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun DateComponents.toDateTimeTz(doThrow: Boolean = false, doAdjust: Boolean = true): DateTimeTz?
Link copied to clipboard
Link copied to clipboard

Returns this date with a local offset. Components might change because of the offset.

Link copied to clipboard

Returns a new local date that will match these components but with a different offset.

Link copied to clipboard
Link copied to clipboard

Converts this date to String using format for representing it

Link copied to clipboard

Converts this date to String using the DateFormat.DEFAULT_FORMAT for representing it

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun Duration.toTimeString(components: Int = 3, addMilliseconds: Boolean = false): String

Formats this Duration into something like 12:30:40.100.

Link copied to clipboard

Returns this date with a local offset. Components might change because of the timeZone.

Link copied to clipboard
infix inline fun Duration.umod(other: Duration): Duration
Link copied to clipboard
inline operator fun Duration.unaryPlus(): Duration
Link copied to clipboard

Generates a right-opened range between two DateTimes

Link copied to clipboard
Link copied to clipboard

Creates a YearMonth representing this year and this month.

Link copied to clipboard

Creates a YearMonth representing this year and this month.