Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Kotlin 1.4 (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz authored Aug 15, 2020
1 parent 86dc7e1 commit f5c4f05
Show file tree
Hide file tree
Showing 23 changed files with 43 additions and 111 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ dependencies {

| Klock | Kotlin | Gradle Metadata | JVM version |
|--------|--------|------------------|-------------|
| 1.12.0 | 1.4.0 | 1.0 | 1.8 |
| 1.8.4 | 1.3.61 | 1.0 | 1.8 |
| 1.8.0 | 1.3.60 | 1.0 | 1.8 |
| 1.7.0 | 1.3.50 | 1.0 | 1.6 |
Expand Down
4 changes: 3 additions & 1 deletion build.extra.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

//apply<com.soywiz.korlibs.KorlibsPlugin>()

/*
subprojects {
afterEvaluate {
tasks {
val jsJar by existing(Jar::class)
//val jsJar by existing(Jar::class)
val npmExtract by creating(Copy::class) {
afterEvaluate {
dependsOn(jsJar)
Expand Down Expand Up @@ -34,3 +35,4 @@ subprojects {
}
}
}
*/
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
}

dependencies {
classpath("com.soywiz.korlibs:easy-kotlin-mpp-gradle-plugin:0.9.3") // Kotlin 1.3.72: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin
classpath("com.soywiz.korlibs:easy-kotlin-mpp-gradle-plugin:0.10.0") // Kotlin 1.4: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kotlin.code.style=official

# version
group=com.soywiz.korlibs.klock
version=1.11.13-SNAPSHOT
version=1.12.0-SNAPSHOT

# bintray location
project.bintray.org=korlibs
Expand All @@ -25,4 +25,4 @@ kotlin.incremental.multiplatform=true
org.gradle.configureondemand=true
kotlin.native.ignoreDisabledTargets=true
enable.android.native=true
android.min.sdk.version=9
android.min.sdk.version=9
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

Expand Down
7 changes: 0 additions & 7 deletions klock/src/androidMain/kotlin/com/soywiz/klock/DateExt.kt

This file was deleted.

12 changes: 0 additions & 12 deletions klock/src/commonMain/kotlin/com/soywiz/klock/DateTimeRange.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ data class DateTimeRange(val from: DateTime, val to: DateTime) : Comparable<Date

val size: TimeSpan get() = to - from

@Suppress("UNUSED_PARAMETER")
@Deprecated("[inclusive] is ignored")
constructor(from: DateTime, to: DateTime, inclusive: Boolean) : this(from, to)

@Deprecated("[inclusive is not used anymore. All the ranges are right-opened.")
val inclusive get() = false
val min get() = from
val max get() = to
/**
Expand Down Expand Up @@ -153,12 +147,6 @@ data class DateTimeRange(val from: DateTime, val to: DateTime) : Comparable<Date

fun List<DateTimeRange>.toStringLongs() = this.map { it.toStringLongs() }.toString()

/**
* Alias for [this] until [other]
*/
@Deprecated("Use until instead", ReplaceWith("this until other"))
operator fun DateTime.rangeTo(other: DateTime) = this until other

/**
* Generates a right-opened range between two [DateTime]s
*/
Expand Down
5 changes: 0 additions & 5 deletions klock/src/commonMain/kotlin/com/soywiz/klock/DateTimeSpan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ data class DateTimeSpan(
operator fun times(times: Int) = this * times.toDouble()
operator fun div(times: Int) = this / times.toDouble()

@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this * times.toDouble()"))
inline operator fun times(times: Number) = this * times.toDouble()
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this / times.toDouble()"))
inline operator fun div(times: Number) = this / times.toDouble()

/** From the date part, all months represented as a [totalYears] [Double] */
val totalYears: Double get() = monthSpan.totalYears

Expand Down
2 changes: 0 additions & 2 deletions klock/src/commonMain/kotlin/com/soywiz/klock/KlockLocale.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ abstract class KlockLocale {
}
*/

@Deprecated("Use months3", ReplaceWith("monthsShort"))
val months3 get() = monthsShort
open val h12Marker = listOf("AM", "OM")

// This might be required for some languages like chinese?
Expand Down
6 changes: 0 additions & 6 deletions klock/src/commonMain/kotlin/com/soywiz/klock/MonthSpan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ inline class MonthSpan(
operator fun times(times: Int) = this * times.toDouble()
operator fun div(times: Int) = this / times.toDouble()

// @TODO: Kotlin/Native is not removing boxes on inline + Number
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this * times.toDouble()"))
inline operator fun times(times: Number) = this * times.toDouble()
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this / times.toDouble()"))
inline operator fun div(times: Number) = this / times.toDouble()

override fun compareTo(other: MonthSpan): Int = this.totalMonths.compareTo(other.totalMonths)

/** Converts this time to String formatting it like "20Y", "20Y 1M", "1M" or "0M". */
Expand Down

This file was deleted.

27 changes: 8 additions & 19 deletions klock/src/commonMain/kotlin/com/soywiz/klock/TimeSpan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,22 @@ package com.soywiz.klock
import com.soywiz.klock.internal.*
import kotlin.math.*

// @TODO: Kotlin/Native is not removing boxes on inline + Number
/** [TimeSpan] representing this number as [nanoseconds] or 1 / 1_000_000_000 [seconds]. */
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this.toDouble().nanoseconds"))
inline val Number.nanoseconds get() = this.toDouble().nanoseconds
inline val Long.nanoseconds get() = TimeSpan.fromNanoseconds(this.toDouble())
/** [TimeSpan] representing this number as [microseconds] or 1 / 1_000_000 [seconds]. */
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this.toDouble().microseconds"))
inline val Number.microseconds get() = this.toDouble().microseconds
inline val Long.microseconds get() = TimeSpan.fromMicroseconds(this.toDouble())
/** [TimeSpan] representing this number as [milliseconds] or 1 / 1_000 [seconds]. */
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this.toDouble().milliseconds"))
inline val Number.milliseconds get() = this.toDouble().milliseconds
inline val Long.milliseconds get() = TimeSpan.fromMilliseconds(this.toDouble())
/** [TimeSpan] representing this number as [seconds]. */
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this.toDouble().seconds"))
inline val Number.seconds get() = this.toDouble().seconds
inline val Long.seconds get() = TimeSpan.fromSeconds((this.toDouble()))
/** [TimeSpan] representing this number as [minutes] or 60 [seconds]. */
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this.toDouble().minutes"))
inline val Number.minutes get() = this.toDouble().minutes
inline val Long.minutes get() = TimeSpan.fromMinutes(this.toDouble())
/** [TimeSpan] representing this number as [hours] or 3_600 [seconds]. */
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this.toDouble().hours"))
inline val Number.hours get() = this.toDouble().hours
inline val Long.hours get() = TimeSpan.fromHours(this.toDouble())
/** [TimeSpan] representing this number as [days] or 86_400 [seconds]. */
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this.toDouble().days"))
inline val Number.days get() = this.toDouble().days
inline val Long.days get() = TimeSpan.fromDays(this.toDouble())
/** [TimeSpan] representing this number as [weeks] or 604_800 [seconds]. */
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this.toDouble().weeks"))
inline val Number.weeks get() = this.toDouble().weeks

// Kotlin/Native is not removing boxes from inline + Number
inline val Long.weeks get() = TimeSpan.fromWeeks(this.toDouble())

/** [TimeSpan] representing this number as [nanoseconds] or 1 / 1_000_000_000 [seconds]. */
inline val Int.nanoseconds get() = TimeSpan.fromNanoseconds(this.toDouble())
Expand Down
10 changes: 10 additions & 0 deletions klock/src/commonMain/kotlin/com/soywiz/klock/hr/HRTimeSpan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ val TimeSpan.hr get() = HRTimeSpan.fromMilliseconds(this.milliseconds)
/** Converts a [HRTimeSpan] into a low-resolution [TimeSpan] */
val HRTimeSpan.timeSpan get() = nanosecondsRaw.nanoseconds

val Long.hrSeconds get() = HRTimeSpan.fromSeconds(this)
val Long.hrMilliseconds get() = HRTimeSpan.fromMilliseconds(this)
val Long.hrMicroseconds get() = HRTimeSpan.fromMicroseconds(this)
val Long.hrNanoseconds get() = HRTimeSpan.fromNanoseconds(this)

val Int.hrSeconds get() = HRTimeSpan.fromSeconds(this)
val Int.hrMilliseconds get() = HRTimeSpan.fromMilliseconds(this)
val Int.hrMicroseconds get() = HRTimeSpan.fromMicroseconds(this)
Expand Down Expand Up @@ -39,6 +44,11 @@ inline class HRTimeSpan constructor(val nanosecondsRaw: Double) : Comparable<HRT
fun fromMilliseconds(value: Int) = fromMilliseconds(value.toDouble())
fun fromMicroseconds(value: Int) = fromMicroseconds(value.toDouble())
fun fromNanoseconds(value: Int) = fromNanoseconds(value.toDouble())

fun fromSeconds(value: Long) = fromSeconds(value.toDouble())
fun fromMilliseconds(value: Long) = fromMilliseconds(value.toDouble())
fun fromMicroseconds(value: Long) = fromMicroseconds(value.toDouble())
fun fromNanoseconds(value: Long) = fromNanoseconds(value.toDouble())
}

val nanosecondsDouble get() = (nanosecondsRaw)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ internal class Moduler(val value: Double) {

fun double(count: Int): Double = double(count.toDouble())
fun int(count: Int): Int = int(count.toDouble())

@Deprecated("Boxing on Kotlin/Native", ReplaceWith("double(count.toDouble())"))
inline fun double(count: Number): Double = double(count.toDouble())
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("int(count.toDouble())"))
inline fun int(count: Number): Int = int(count.toDouble())

}

internal infix fun Double.intDiv(other: Double) = floor(this / other)
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ data class WMonthSpan(val value: MonthSpan) : Comparable<WMonthSpan>, Serializab
operator fun times(times: Int) = this * times.toDouble()
operator fun div(times: Int) = this / times.toDouble()

@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this * times.toDouble()"))
inline operator fun times(times: Number) = this * times.toDouble()
@Deprecated("Boxing on Kotlin/Native", ReplaceWith("this / times.toDouble()"))
inline operator fun div(times: Number) = this / times.toDouble()

override fun compareTo(other: WMonthSpan): Int = this.value.compareTo(other.value)

/** Converts this time to String formatting it like "20Y", "20Y 1M", "1M" or "0M". */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class DateTimeRangeSetTest {

val fast = DateTimeRangeSet.Fast.minus(r1, r2).toStringLongs()
val slow = DateTimeRangeSet.Slow.minus(r1, r2).toStringLongs()
println(r1)
println(r2)
println("fast: $fast")
println("slow: $slow")
//println(r1)
//println(r2)
//println("fast: $fast")
//println("slow: $slow")
assertEquals(fast, slow)
}

Expand All @@ -89,10 +89,10 @@ class DateTimeRangeSetTest {
val fast = DateTimeRangeSet.Fast.intersection(r1, r2).toStringLongs()
val slow = DateTimeRangeSet.Slow.intersection(r1, r2).toStringLongs()
//val slow = DateTimeRangeSet.Fast.intersection(r1, r2).toStringLongs()
println(r1)
println(r2)
println("fast: $fast")
println("slow: $slow")
//println(r1)
//println(r2)
//println("fast: $fast")
//println("slow: $slow")
assertEquals(fast, slow)

val fast2 = DateTimeRangeSet.Fast.intersection(r2, r1).toStringLongs()
Expand Down Expand Up @@ -153,4 +153,4 @@ class DateTimeRangeSetTest {
assertEquals(100.milliseconds, range(100, 200).size)
assertEquals(200.milliseconds, DateTimeRangeSet(range(100, 200), range(150, 300)).size)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlin.test.assertEquals
class DateTimeRangeTest {
val format = ISO8601.DATETIME_COMPLETE
fun String.date() = format.parseUtc(this)
fun range(from: Int, to: Int) = (DateTime.EPOCH + from.milliseconds)..(DateTime.EPOCH + to.milliseconds)
fun range(from: Int, to: Int) = (DateTime.EPOCH + from.milliseconds) until (DateTime.EPOCH + to.milliseconds)

@Test
fun test() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.soywiz.klock

import com.soywiz.klock.wrapped.WDateTime
import com.soywiz.klock.wrapped.wrapped
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand All @@ -8,8 +10,8 @@ class SerializableDateTimeTest {
@Test
fun testSerializableInstances() {
@Suppress("USELESS_IS_CHECK")
assertEquals(true, DateTime.now().serializable() is SerializableDateTime)
assertEquals(true, DateTime.now().wrapped is WDateTime)
@Suppress("USELESS_IS_CHECK")
assertEquals(true, DateTime.nowLocal() is DateTimeTz)
}
}
}
10 changes: 0 additions & 10 deletions klock/src/jsMain/kotlin/com/soywiz/klock/internal/DateExt.kt

This file was deleted.

7 changes: 0 additions & 7 deletions klock/src/jvmMain/kotlin/com/soywiz/klock/DateExt.kt

This file was deleted.

0 comments on commit f5c4f05

Please sign in to comment.