Package com.soywiz.klock

Types

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
class DateException(msg: String) : RuntimeException

An exception for Date operations.

Link copied to clipboard
interface DateFormat

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
data class DateTimeRangeSet : Serializable
Link copied to clipboard
data class DateTimeSpan(val monthSpan: MonthSpan, val timeSpan: TimeSpan) : Comparable<DateTimeSpan> , Serializable

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

Link copied to clipboard
interface DateTimeSpanFormat
Link copied to clipboard
class DateTimeTz : Comparable<DateTimeTz> , Serializable

DateTime with an associated TimezoneOffset

Link copied to clipboard
enum DayOfWeek : Enum<DayOfWeek> , Serializable

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
value class Frequency(val hertz: Double)
Link copied to clipboard
object ISO8601
Link copied to clipboard
abstract class KlockLocale
Link copied to clipboard
data class KlockLocaleContext(val gender: KlockLocaleGender = KlockLocaleGender.Neuter)
Link copied to clipboard
enum KlockLocaleGender : Enum<KlockLocaleGender>
Link copied to clipboard
enum Month : Enum<Month> , Serializable

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 PatternDateFormat @JvmOverloads constructor(    val format: String,     val locale: KlockLocale? = null,     val tzNames: TimezoneNames = TimezoneNames.DEFAULT,     val options: PatternDateFormat.Options = Options.DEFAULT) : DateFormat, Serializable
Link copied to clipboard
data class PatternTimeFormat(val format: String, val options: PatternTimeFormat.Options = Options.DEFAULT) : TimeFormat, Serializable
Link copied to clipboard
object PerformanceCounter

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: TimeSpan) : Comparable<Time> , Serializable

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

Link copied to clipboard
data class TimedResult<T>(val result: T, val time: TimeSpan)

Represents a result associated to a time.

Link copied to clipboard
interface TimeFormat
Link copied to clipboard
interface TimeProvider

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

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

Represents a span of time, with milliseconds precision.

Link copied to clipboard
data class TimezoneNames(val namesToOffsets: Map<String, TimeSpan>) : 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.

Functions

Link copied to clipboard
fun blockingSleep(time: TimeSpan)
fun blockingSleep(time: HRTimeSpan)

Sleeps the thread during the specified time. Spinlocks on JS

Link copied to clipboard
fun DateTime.clamp(min: DateTime, max: DateTime): DateTime
fun TimeSpan.clamp(min: TimeSpan, max: TimeSpan): TimeSpan
Link copied to clipboard
inline fun TimeSpan.coalesce(block: () -> TimeSpan): TimeSpan
Link copied to clipboard
fun Year.first(dayOfWeek: DayOfWeek): DateTime
Link copied to clipboard
fun DateFormat.format(dd: Date): String
fun DateFormat.format(dd: DateTime): String
fun DateFormat.format(date: Double): String
fun DateFormat.format(date: Long): String
fun DateTimeSpanFormat.format(dd: MonthSpan): String
fun DateTimeSpanFormat.format(dd: TimeSpan): String
fun TimeFormat.format(time: Time): String
fun TimeFormat.format(time: Double): String
fun TimeFormat.format(time: Long): String
fun DateTime.format(format: String, locale: KlockLocale): String
fun DateTimeTz.format(format: String, locale: KlockLocale): String
Link copied to clipboard
fun Date.inThisWeek(dayOfWeek: DayOfWeekWithLocale): Date
fun Date.inThisWeek(dayOfWeek: DayOfWeek, locale: KlockLocale = KlockLocale.default): Date
Link copied to clipboard
fun max(a: DateTime, b: DateTime): DateTime
fun max(a: TimeSpan, b: TimeSpan): TimeSpan
Link copied to clipboard
inline fun TimeProvider.measure(block: () -> Unit): TimeSpan
Link copied to clipboard
inline fun measureTime(callback: () -> Unit): TimeSpan

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

inline fun <T> measureTime(callback: () -> T, handleTime: (TimeSpan) -> Unit): T
Link copied to clipboard
inline fun <T> measureTimeWithResult(callback: () -> T): TimedResult<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
fun min(a: DateTime, b: DateTime): DateTime
fun min(a: TimeSpan, b: TimeSpan): TimeSpan
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: TimeSpan): Date
Link copied to clipboard
fun DateFormat.parse(str: String): DateTimeTz
fun DateTimeSpanFormat.parse(str: String): DateTimeSpan
fun TimeFormat.parse(str: String): TimeSpan
Link copied to clipboard
fun DateFormat.parseDate(str: String): Date
Link copied to clipboard
fun TimeFormat.parseTime(str: String): Time
Link copied to clipboard
fun DateFormat.parseUtc(str: String): DateTime
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: TimeSpan): Date
operator fun Time.plus(span: TimeSpan): Time
Link copied to clipboard
fun TimeSpan.roundMilliseconds(): TimeSpan
Link copied to clipboard
fun TimeSpan.toFrequency(): Frequency
Link copied to clipboard
fun Iterable<DateTimeRange>.toRangeSet(): DateTimeRangeSet
Link copied to clipboard
fun List<DateTimeRange>.toStringLongs(): String
Link copied to clipboard
fun TimeSpan.toTimeString(components: Int = 3, addMilliseconds: Boolean = false): String

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

Link copied to clipboard
infix fun DateTime.until(other: DateTime): DateTimeRange

Generates a right-opened range between two DateTimes

Link copied to clipboard
fun DayOfWeek.withLocale(locale: KlockLocale): DayOfWeekWithLocale
Link copied to clipboard
fun Year.withMonth(month: Month): YearMonth

Creates a YearMonth representing this year and this month.

Link copied to clipboard
fun Month.withYear(year: Year): YearMonth

Creates a YearMonth representing this year and this month.

Properties

Link copied to clipboard
val Long.days: TimeSpan

TimeSpan representing this number as days or 86_400 seconds.

val Float.days: TimeSpan

TimeSpan representing this number as days or 86_400 seconds.

val Int.days: TimeSpan

TimeSpan representing this number as days or 86_400 seconds.

val Double.days: TimeSpan

TimeSpan representing this number as days or 86_400 seconds.

Link copied to clipboard
val Long.hours: TimeSpan

TimeSpan representing this number as hours or 3_600 seconds.

val Float.hours: TimeSpan

TimeSpan representing this number as hours or 3_600 seconds.

val Int.hours: TimeSpan

TimeSpan representing this number as hours or 3_600 seconds.

val Double.hours: TimeSpan

TimeSpan representing this number as hours or 3_600 seconds.

Link copied to clipboard
val TimeSpan.hz: Frequency
val Int.hz: Frequency
val Double.hz: Frequency
Link copied to clipboard
val infiniteTimes: NumberOfTimes
Link copied to clipboard
val Long.microseconds: TimeSpan

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

val Float.microseconds: TimeSpan

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

val Int.microseconds: TimeSpan

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

val Double.microseconds: TimeSpan

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

Link copied to clipboard
val Long.milliseconds: TimeSpan

TimeSpan representing this number as milliseconds or 1 / 1_000 seconds.

val Float.milliseconds: TimeSpan

TimeSpan representing this number as milliseconds or 1 / 1_000 seconds.

val Int.milliseconds: TimeSpan

TimeSpan representing this number as milliseconds or 1 / 1_000 seconds.

val Double.milliseconds: TimeSpan

TimeSpan representing this number as milliseconds or 1 / 1_000 seconds.

Link copied to clipboard
val Long.minutes: TimeSpan

TimeSpan representing this number as minutes or 60 seconds.

val Float.minutes: TimeSpan

TimeSpan representing this number as minutes or 60 seconds.

val Int.minutes: TimeSpan

TimeSpan representing this number as minutes or 60 seconds.

val Double.minutes: TimeSpan

TimeSpan representing this number as minutes or 60 seconds.

Link copied to clipboard
val Int.months: MonthSpan

Creates a MonthSpan representing these months.

val MonthSpan.months: Int

Months part of this MonthSpan as integer

Link copied to clipboard
val Long.nanoseconds: TimeSpan

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

val Float.nanoseconds: TimeSpan

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

val Int.nanoseconds: TimeSpan

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

val Double.nanoseconds: TimeSpan

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

Link copied to clipboard
val TimeSpan.offset: TimezoneOffset
Link copied to clipboard
val Long.seconds: TimeSpan

TimeSpan representing this number as seconds.

val Float.seconds: TimeSpan

TimeSpan representing this number as seconds.

val Int.seconds: TimeSpan

TimeSpan representing this number as seconds.

val Double.seconds: TimeSpan

TimeSpan representing this number as seconds.

Link copied to clipboard
val Int.times: NumberOfTimes
Link copied to clipboard
val TimeSpan.timesPerSecond: Frequency
val Int.timesPerSecond: Frequency
val Double.timesPerSecond: Frequency
Link copied to clipboard
val MonthSpan.totalYears: Double

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

Link copied to clipboard
val DateTime.weekOfYear0: Int
val DateTimeTz.weekOfYear0: Int
Link copied to clipboard
val DateTime.weekOfYear1: Int
val DateTimeTz.weekOfYear1: Int
Link copied to clipboard
val Long.weeks: TimeSpan

TimeSpan representing this number as weeks or 604_800 seconds.

val Float.weeks: TimeSpan

TimeSpan representing this number as weeks or 604_800 seconds.

val Int.weeks: TimeSpan

TimeSpan representing this number as weeks or 604_800 seconds.

val Double.weeks: TimeSpan

TimeSpan representing this number as weeks or 604_800 seconds.

Link copied to clipboard
val Int.years: MonthSpan

Creates a MonthSpan representing these years.

val MonthSpan.years: Int

Years part of this MonthSpan as integer