korlibs-archive / klock Goto Github PK
View Code? Open in Web Editor NEWMultiplatform Date and time library for Kotlin
Home Page: https://korlibs.soywiz.com/klock/
License: Creative Commons Zero v1.0 Universal
Multiplatform Date and time library for Kotlin
Home Page: https://korlibs.soywiz.com/klock/
License: Creative Commons Zero v1.0 Universal
I am not sure if I am doing something wrong, but something seems strange with the below. Doing something similar with java.time.LocalDateTime gives the expected results (i.e. not as below).
00:10 pm is not a valid time, I believe it should be 12:10 pm.
The code is as follows, with the date2 being formatted (I believe) incorrectly.
val dateFormat = DateFormat("yyyy-mm-dd HH:mm z")
val date1: DateTimeTz = dateFormat.parse("2019-10-17 11:10 +12")
println(date1.local.toString("hh:mm a")) // Gives 11:10 am
val date2: DateTimeTz = dateFormat.parse("2019-10-17 12:10 +12")
println(date2.local.toString("hh:mm a")) // Gives 00:10 pm, I believe it should be 12:10 pm
val date3: DateTimeTz = dateFormat.parse("2019-10-17 13:10 +12")
println(date3.local.toString("hh:mm a")) // Gives 01:10 pm
targets {
fromPreset(presets.android, 'android')
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
fromPreset(iOSTarget, 'ios') {
compilations.main.outputKinds('FRAMEWORK')
}
}
Cannot choose between the following configurations of com.soywiz:klock:1.0.0:
- iosArm32-api
- iosArm64-api
- iosX64-api
- js-api
- js-runtime
- jvm-api
- jvm-runtime
- linuxX64-api
- macosX64-api
- metadata-api
- mingwX64-api
All of them match the consumer attributes:
- Configuration 'iosArm32-api':
- Found artifactType 'org.jetbrains.kotlin.klib' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'kotlin-api' but wasn't required.
- Found org.jetbrains.kotlin.native.target 'ios_arm32' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
- Configuration 'iosArm64-api':
- Found artifactType 'org.jetbrains.kotlin.klib' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'kotlin-api' but wasn't required.
- Found org.jetbrains.kotlin.native.target 'ios_arm64' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
- Configuration 'iosX64-api':
- Found artifactType 'org.jetbrains.kotlin.klib' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'kotlin-api' but wasn't required.
- Found org.jetbrains.kotlin.native.target 'ios_x64' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
- Configuration 'js-api':
- Found artifactType 'jar' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'kotlin-api' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'js' but wasn't required.
- Configuration 'js-runtime':
- Found artifactType 'jar' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'kotlin-runtime' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'js' but wasn't required.
- Configuration 'jvm-api':
- Found artifactType 'jar' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'java-api' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'jvm' but wasn't required.
- Configuration 'jvm-runtime':
- Found artifactType 'jar' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'java-runtime-jars' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'jvm' but wasn't required.
- Configuration 'linuxX64-api':
- Found artifactType 'org.jetbrains.kotlin.klib' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'kotlin-api' but wasn't required.
- Found org.jetbrains.kotlin.native.target 'linux_x64' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
- Configuration 'macosX64-api':
- Found artifactType 'org.jetbrains.kotlin.klib' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'kotlin-api' but wasn't required.
- Found org.jetbrains.kotlin.native.target 'macos_x64' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
- Configuration 'metadata-api':
- Found artifactType 'jar' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'kotlin-api' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'common' but wasn't required.
- Configuration 'mingwX64-api':
- Found artifactType 'org.jetbrains.kotlin.klib' but wasn't required.
- Found org.gradle.status 'release' but wasn't required.
- Found org.gradle.usage 'kotlin-api' but wasn't required.
- Found org.jetbrains.kotlin.native.target 'mingw_x64' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'native' but wasn't required.
I tried the new optional pattern, which is awesome, like this:
https://github.com/clhols/drchannels/blob/master/drapi/src/commonMain/kotlin/DateSerializer.kt
But it throws this exception when running on iOS:
kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap@82aaf188 at 0 DR channels 0x000000010497802c kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 84 at 1 DR channels 0x00000001049770bc kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 84 at 2 DR channels 0x00000001049a5aa0 kfun:kotlin.native.concurrent.InvalidMutabilityException.<init>(kotlin.String)kotlin.native.concurrent.InvalidMutabilityException + 84 at 3 DR channels 0x00000001049a5e8c ThrowInvalidMutabilityException + 484 at 4 DR channels 0x0000000104d566e4 MutationCheck + 116 at 5 DR channels 0x000000010498c358 kfun:kotlin.collections.HashMap.<set-length>#internal + 88 at 6 DR channels 0x0000000104990500 kfun:kotlin.collections.HashMap.addKey$stdlib(#GENERIC)ValueType + 932 at 7 DR channels 0x000000010498d3cc kfun:kotlin.collections.HashMap.put(#GENERIC;#GENERIC)#GENERIC? + 224 at 8 DR channels 0x0000000104be5df4 kfun:com.soywiz.klock.internal.increment$klock@kotlin.collections.MutableMap<#GENERIC,kotlin.Int>.(#GENERIC)Generic + 468 at 9 DR channels 0x0000000104bdf934 kfun:com.soywiz.klock.PatternDateFormat.<init>$lambda-0#internal + 1180 at 10 DR channels 0x0000000104be183c kfun:com.soywiz.klock.PatternDateFormat.$<init>$lambda-0$FUNCTION_REFERENCE$33.invoke#internal + 132 at 11 DR channels 0x00000001049a6d28 kfun:kotlin.native.concurrent.FreezeAwareLazyImpl.<get-value>()#GENERIC + 936 at 12 DR channels 0x0000000104bd91a0 kfun:com.soywiz.klock.PatternDateFormat.<get-chunks>$klock()kotlin.collections.List<kotlin.String> + 276 at 13 DR channels 0x0000000104bdfcec kfun:com.soywiz.klock.PatternDateFormat.<init>$lambda-1#internal + 340 at 14 DR channels 0x0000000104be19c0 kfun:com.soywiz.klock.PatternDateFormat.$<init>$lambda-1$FUNCTION_REFERENCE$34.invoke#internal + 132 at 15 DR channels 0x00000001049a6d28 kfun:kotlin.native.concurrent.FreezeAwareLazyImpl.<get-value>()#GENERIC + 936 at 16 DR channels 0x0000000104bd932c kfun:com.soywiz.klock.PatternDateFormat.<get-regexChunks>$klock()kotlin.collections.List<kotlin.String> + 276 at 17 DR channels 0x0000000104be0fa8 kfun:com.soywiz.klock.PatternDateFormat.<init>$lambda-2#internal + 372 at 18 DR channels 0x0000000104be1b44 kfun:com.soywiz.klock.PatternDateFormat.$<init>$lambda-2$FUNCTION_REFERENCE$35.invoke#internal + 132 at 19 DR channels 0x00000001049a6d28 kfun:kotlin.native.concurrent.FreezeAwareLazyImpl.<get-value>()#GENERIC + 936 at 20 DR channels 0x0000000104bd94b8 kfun:com.soywiz.klock.PatternDateFormat.<get-rx2>$klock()kotlin.text.Regex + 276 at 21 DR channels 0x0000000104bdc0dc kfun:com.soywiz.klock.PatternDateFormat.tryParse(kotlin.String;kotlin.Boolean)com.soywiz.klock.DateTimeTz? + 1468 at 22 DR channels 0x0000000104bcb468 kfun:[email protected].(kotlin.String)com.soywiz.klock.DateTimeTz + 356 at 23 DR channels 0x0000000104c3115c kfun:dk.youtec.drapi.DateSerializer.deserialize(kotlinx.serialization.Decoder)ValueType + 400 at 24 DR channels 0x0000000104c31458 kfun:dk.youtec.drapi.DateSerializer.$<bridge-UNNN>deserialize(kotlinx.serialization.Decoder)ValueType(kotlinx.serialization.Decoder)kotlin.Any? + 160 at 25 DR channels 0x0000000104c1a7a0 kfun:kotlinx.serialization.json.internal.decodeSerializableValuePolymorphic$kotlinx-serialization-runtime@kotlinx.serialization.json.JsonInput.(kotlinx.serialization.DeserializationStrategy<#GENERIC>)Generic + 1972 at 26 DR channels 0x0000000104c1b338 kfun:kotlinx.serialization.json.internal.StreamingJsonInput.decodeSerializableValue(kotlinx.serialization.DeserializationStrategy<#GENERIC>)Generic + 164 at 27 DR channels 0x0000000104becb84 kfun:kotlinx.serialization.ElementValueDecoder.decodeSerializableElement(kotlinx.serialization.SerialDescriptor;kotlin.Int;kotlinx.serialization.DeserializationStrategy<#GENERIC>)Generic + 212 at 28 DR channels 0x0000000104c4fb6c kfun:dk.youtec.drapi.MuScheduleBroadcast.$serializer.deserialize(kotlinx.serialization.Decoder)dk.youtec.drapi.MuScheduleBroadcast + 1612
Hi, i am facing problem after updated IntelliJ. I also have updated my kotlin version to 1.3.60
IntelliJ IDEA 2019.2.1 (Community Edition)
Build #IC-192.6262.58, built on August 20, 2019
Runtime version: 11.0.3+12-b304.39 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Previous version i never face any issue, but in this build, i face this error. Now I am using version 1.8.0
Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option
FAILURE: Build failed with an exception.
Here is the code in my commonMain folder
var timeZone = TimeSpan((8.hours).milliseconds)
I have changed my project JVM version setting to 1.6.
Is there anything that I have to do to solve this issue? Hopefully you can guide me on this. Thanks!
At klock version 1.1.1, this code is not working properly.
val output = DateFormat("yyyy年MM月dd日").format(DateTime(2019, 4, 12))
The result, output is yyyy年MM月dd日
.
Expected result is 2019年04月12日
.
I'm not able to reference klock in a multiplatform gradle build. Not sure what I'm doing wrong. Here's a minimal example:
build.gradle:
buildscript {
ext.repos = {
jcenter()
mavenCentral()
maven { url "https://dl.bintray.com/soywiz/soywiz" }
}
repositories repos
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11'
}
}
apply plugin: 'org.jetbrains.kotlin.multiplatform'
repositories repos
kotlin {
targets {
fromPreset(presets.jvm, 'jvm')
fromPreset(presets.js, 'js')
}
sourceSets {
commonMain {
dependencies {
api "com.soywiz:klock:1.0.0"
}
}
jvmMain {
dependencies {
api "com.soywiz:klock-jvm:1.0.0"
}
}
jsMain {
dependencies {
api "com.soywiz:klock-js:1.0.0"
}
}
}
}
src/commonMain/kotlin/main.kt
import com.soywiz.klock.DateTime
val dateTime = DateTime.now()
:compileKotlinMetadata (Thread[Execution worker for ':',5,main]) started.
e: /Users/asdf/klock/src/commonMain/kotlin/main.kt: (2, 8): Unresolved reference: com
e: /Users/asdf/klock/src/commonMain/kotlin/main.kt: (5, 16): Unresolved reference: DateTime
> Task :compileKotlinMetadata FAILED
Making a release build of an Android app works just fine. But when trying a debug build, I get the following Gradle error.
> Could not resolve all files for configuration ':drapi:debugRuntimeClasspath'.
> Could not resolve com.soywiz.korlibs.klock:klock-android:1.5.0.
Required by:
project :drapi
> Unable to find a matching variant of com.soywiz.korlibs.klock:klock-android:1.5.0:
- Variant 'android-releaseApiElements' capability com.soywiz.korlibs.klock:klock-android:1.5.0:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found incompatible value 'release'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Found org.gradle.status 'release' but wasn't required.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'android-releaseRuntimeElements' capability com.soywiz.korlibs.klock:klock-android:1.5.0:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found incompatible value 'release'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Found org.gradle.status 'release' but wasn't required.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found compatible value 'androidJvm'.
- Variant 'metadata-api' capability com.soywiz.korlibs.klock:klock-android:1.5.0:
- Incompatible attributes:
- Required org.gradle.usage 'java-runtime' and found incompatible value 'kotlin-api'.
- Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'common'.
- Other attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Found org.gradle.status 'release' but wasn't required.
The app:
https://github.com/clhols/drchannels/tree/klock-150
Execute:
./gradlew aMD
How to get date from string?
We have some problems integrating Klock version 1.4.0 into our Kotlin multiplatform project. We must be doing something wrong but cannot pinpoint this at the moment. Our project structure is as follows (see als https://github.com/jcraane/KotlinNativeStarter) with the following dependencies:
Root project
'settings.gradle'
enableFeaturePreview("GRADLE_METADATA")
common (our common code)
'build.gradle'
commonMain -> api "com.soywiz.korlibs.klock:klock:$klockVersion"
iosMain -> implementation("com.soywiz:klock-iosx64:$klockVersion")
android
app (Android module)
'build.gradle'
implementation("com.soywiz:klock-locale-android:1.4.0")
implementation("com.soywiz:klock-android:1.4.0")
iosApp
We use the DateTime classes in the common, IOS and Android project. Compilation works fine with the above settings but if we try to run the Android application we get the following error (for all duplicate classes:
java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class com.soywiz.klock.BuildConfig found in modules classes.jar (com.soywiz.korlibs.klock:klock-android-debug:1.4.0) and classes.jar (com.soywiz:klock-android:1.4.0)
Is there something wrong with our configuration?
Thanks!
I am trying to add klock maven repository to my maven project
<repositories> <repository> <id>korlibs</id> <name>korlibs</name> <url>https://dl.bintray.com/korlibs/korlibs</url> </repository> </repositories>
My Intellij and cmd maven doesn't recognize it and shows an error.
For example, at 12:00 at MSK(GMT+0300) function will return 10:00 GMT+0300. Expected result is 12:00 GMT+0300
I am led to believe this is intentional. So, do I include the jvm target for android as well?
After formatting a DateTime instance, and printing it out the hour is incorrect (exactly one hour behind):
Current Timestamp: 2019-09-30_00:42
Here is the output after running the date
command (on Linux) about two minutes later:
Mon Sep 30 13:44:39 NZDT 2019
Used the following for converting a DateTime instance to text:
fun DateTime.toText(): String {
// Use the following date time format: year-month-day hour:minute. Here is some example output: 2018-01-23_20:35.
val pattern = "yyyy-MM-dd_HH:mm"
return format(pattern)
}
For example parsing 2019-05-09 by pattern yyyy-MM-dd in MSK (UTC+0300) will return Thu, 09 May 2019 00:00:00 UTC, expected result is Thu, 09 May 2019 00:00:00 GMT+0300
It will help to parse user input. Default behavior for Java date parser is to use local timezone.
At klock version 1.1.1, this code throws NumberFormatException. Is this expected behvior ?
DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").parse("2019-04-15T17:28:46.862+0900")
java.lang.NumberFormatException: For input string: "862+0900"
Note: the format , and yyyy-MM-dd'T'HH:mm:ss.SSSZ
works fine for +0900
yyyy-MM-dd'T'HH:mm:ss.SSSXXX
works fine for +09:00
.
→ yyyy-MM-dd'T'HH:mm:ss.SSSZ
is no Exception, but parsed that time as UTC, so it's also wrong result.
When parse:
DateFormat("yyyy-MM-dd'T'HH:mm:ss").parse("2000-12-31T00:00:00")
have error when get dayOfMonth
java.lang.IllegalStateException: Invalid dayOfYear=36525, isLeap=false
This error on all time in 31-12-2000
Is there anything against to let DateTime implement Comparable?
I'm using Klock in a cross-platform project atm and like it :) Thanks!
Currently, TimeZone is ignored during parsing...
In my usage of Klock, I need it to parse a timestamp that may or may not have the milliseconds field present. Having support for it in the formatter would be a great help.
Hi,
I think use of metadata is the right way to go.
However, there seems to be an issue,
I am depending on klock (transitively) via other libs of mine.
And I get this error,
not sure why the android libs are getting in the way?
Execution failed for task ':myModule:compileJava'.
> Could not resolve all files for configuration ':myModule:compileClasspath'.
> Could not resolve com.soywiz.korlibs.klock:klock:1.5.0.
Required by:
project :myModule > project :myModule-api > myGroup:otherModule-api:3.1.0-SNAPSHOT > myGroup:otherModule-api-jvm8:3.1.0-SNAPSHOT
> Cannot choose between the following variants of com.soywiz.korlibs.klock:klock:1.5.0:
- android-debugApiElements
- android-debugRuntimeElements
- android-releaseApiElements
- android-releaseRuntimeElements
- jvm-api
- jvm-runtime
All of them match the consumer attributes:
- Variant 'android-debugApiElements' capability com.soywiz.korlibs.klock:klock:1.5.0:
- Unmatched attributes:
- Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
- Required org.gradle.dependency.bundling 'external' but no value provided.
- Required org.gradle.jvm.version '8' but no value provided.
- Found org.gradle.status 'release' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.
- Compatible attribute:
- Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
- Variant 'android-debugRuntimeElements' capability com.soywiz.korlibs.klock:klock:1.5.0:
- Unmatched attributes:
- Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
- Required org.gradle.dependency.bundling 'external' but no value provided.
- Required org.gradle.jvm.version '8' but no value provided.
- Found org.gradle.status 'release' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.
- Compatible attribute:
- Required org.gradle.usage 'java-api' and found compatible value 'java-runtime'.
- Variant 'android-releaseApiElements' capability com.soywiz.korlibs.klock:klock:1.5.0:
- Unmatched attributes:
- Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
- Required org.gradle.dependency.bundling 'external' but no value provided.
- Required org.gradle.jvm.version '8' but no value provided.
- Found org.gradle.status 'release' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.
- Compatible attribute:
- Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
- Variant 'android-releaseRuntimeElements' capability com.soywiz.korlibs.klock:klock:1.5.0:
- Unmatched attributes:
- Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
- Required org.gradle.dependency.bundling 'external' but no value provided.
- Required org.gradle.jvm.version '8' but no value provided.
- Found org.gradle.status 'release' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.
- Compatible attribute:
- Required org.gradle.usage 'java-api' and found compatible value 'java-runtime'.
- Variant 'jvm-api' capability com.soywiz.korlibs.klock:klock:1.5.0:
- Unmatched attributes:
- Required org.gradle.dependency.bundling 'external' but no value provided.
- Required org.gradle.jvm.version '8' but no value provided.
- Found org.gradle.status 'release' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'jvm' but wasn't required.
- Compatible attribute:
- Required org.gradle.usage 'java-api' and found compatible value 'java-api-jars'.
- Variant 'jvm-runtime' capability com.soywiz.korlibs.klock:klock:1.5.0:
- Unmatched attributes:
- Required org.gradle.dependency.bundling 'external' but no value provided.
- Required org.gradle.jvm.version '8' but no value provided.
- Found org.gradle.status 'release' but wasn't required.
- Found org.jetbrains.kotlin.platform.type 'jvm' but wasn't required.
- Compatible attribute:
- Required org.gradle.usage 'java-api' and found compatible value 'java-runtime-jars'.
This is not strictly related to klock; but this is the only library I care to use in a kotlin multiplatform project.
Please could you be more specific where to put:
implementation "com.soywiz:klock:$klockVersion" ?
I struggle to keep up with gradle changes in kotlin multiplatform project...
I'm using default multiplatform project created by intelliJ (JVM/JS).
This is an excerpt from my unique build.gradle:
plugins {
id 'kotlin-multiplatform' version '1.3.21'
}
Are there any plans to publish Klock's Kotlin/JS library on NPM? This would make it easier for JS libraries built using Kotlin/JS to be published on NPM and pull in Klock as a downstream dependency rather than re-packaging it alongside dependent code.
Currently, a Kotlin/JS publication that wants to leverage Klock as a dependency needs to include it as part of the artifact, rather than just a reference in its package.json file and allowing downstream users to install it as part of a standard npm install
routine.
@soywiz
Not sure if this is the best place to ask, but maybe others are interested too.
As far as I have seen, you are the only person actually creating libraries for all platform's that Kotlin multiplatform supports. I am just curious, what is your setup to build and publish your libraries... This isn't as hard as before now that kotlin 1.3.30 can "In addition to that, Windows and macOS users can cross-compile their Kotlin/Native programs to Linux x86-64, arm32, as well as Android and Raspberry PI devices."
But still, you need to at least switch between windows and mac to build and publish. How are you managing this (in a timely manner)? What I am most curious about is if you have an automated way to do this... or are you just using virtual desktops or multiple computers?
Something like Map<Int, String>
for specifying month/DoW names for different languages.
ISO8601 widely used format in many countries / systems / interchange formats / etc, so built-in support for it would be very nice.
{
"main": "klock-root-klock.js",
"dependencies": {
"kotlin": "%%%KOTLIN_VERSION!!!"
},
"name": "klock-root-klock",
"version": "0.0.0-VERSION"
}
Breaks multiplatform build when targetting Kotlin/JS and adding some dependencies from NPM using the 1.3.40+ Kotlin MPP/JS Gradle Plugins. Of course if only importing from Maven the package.json does not comes into play and the issue is not present.
Trying to build the library even without NPM imports triggers the error as well.
Let me know what you want/don't want to change.
The new MPP plugin will skip tasks for targets that are not supported by the host so this should no longer be needed. You can just define all the targets klock supports at once.
Here is an example of running JS tests with qunit, want me to set this up?
I think the tools.gradle
file can be simplified (if not removed) by setting up the config like this
Can we enable gradle metadata and update to gradle 4.7 to support native publishing?
I've found that the bintray plugin can be replaced by just using the maven-publish
plugin. See here
Hey,
I am trying to use klock in a multi platform project and a depending JS project.
This works fine with 1.7.0 dependencies. But updating to anything later results in different errors (related to the npm-install Gradle task).
I honestly don't know what might be wrong, I just wanted to ask if there have been any changes I don't understand. Especially because the version number mentioned on the home page is 1.7.0
Hello,
I followed the instructions in the README, but I'm getting the following error :
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':shared:compileKotlinIOS'.
> Could not resolve all task dependencies for configuration ':shared:iOSCompileKlibraries'.
> Could not resolve com.soywiz.korlibs.klock:klock:1.4.0.
Required by:
project :shared
> Could not resolve com.soywiz.korlibs.klock:klock:1.4.0.
> Could not parse module metadata https://dl.bintray.com/korlibs/korlibs/com/soywiz/korlibs/klock/klock/1.4.0/klock-1.4.0.module
> Unsupported format version '1.0' specified in module metadata. This version of Gradle supports format version 0.4 only.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 5s
For reference, here are the instructions that I followed.
def klockVersion = "1.4.0"
repositories {
maven { url "https://dl.bintray.com/korlibs/korlibs" }
}
kotlin {
sourceSets {
commonMain {
dependencies {
implementation "com.soywiz.korlibs.klock:klock:$klockVersion" // Common
}
}
}
}
settings.gradle
enableFeaturePreview('GRADLE_METADATA')
It will be grate to have classes for truncated date (year+month+day) and pure time (hour+minute+second)
I can't seem to build against iOS using Kotlin 1.3.61
w: skipping /Users/.../.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-ios-iosarm64/1.2.4/.../ktor-client-ios.klib. The abi versions don't match. Expected '[17]', found '14'
w: The compiler versions don't match either. Expected '[]', found '1.3.50-release-11850'
I am using:
api "com.soywiz.korlibs.klock:klock:1.8.3"
Hi, i am new to the Kotlin Multiplatform, and found this amazing library.
I am having problem to import the dependency into my common.kt file
here is my build.gradle file
def klockVersion = "1.4.0"
repositories {
jcenter()
}
kotlin {
targets {
final def iOSTarget = presets.iosArm64
fromPreset(iOSTarget, 'iOS') {
binaries {
framework('SharedCode')
}
}
fromPreset(presets.jvm, 'android')
}
sourceSets {
commonMain {
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-common'
implementation 'com.soywiz.korlibs.klock:klock:1.4.0'
}
}
androidMain.dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib'
}
}
}
in my common.kt
import com. // unresolved reference
Can anyone guide me on this issue please ?
Any guide given much appreciated. Thanks
What is the planning regarding updating Klock to work with Kotlin 1.3.40?
Thanks!
Hi,
I'm doing some testing with the DateTimeSpan class and I've been having some issues with the calculations.
if a have the following
val startDate = DateTime.fromString("Mon, 01 Jan 2019 00:00:00 UTC").local
val endDate = DateTime.fromString("Sat, 01 Sep 2019 00:00:00 UTC").local
val span = (startDate until endDate).span
assertEquals("8", span.totalMonths) //Fails due to span calculation being '7M 4W 3D'
It fails because it's not calculating the 8 months difference there is between the two dates.
A lot of Kotlin devs are probably used to this API especially for conversion between different units of time. Would you be interested in a (probably very small) PR to add a multiplatform version?
https://korlibs.soywiz.com/klock/
At least setup instruction should be updated. I had a difficult time finding the correct way to set up the klock dependency.
Add these tests, and you'll immediately see what I'm talking about:
@Test
fun dateTime_shouldGiveTheCorrectYearWhenGivenUnixTimestamp() {
val dt = DateTime.fromUnix(1563482699) //July 18, 2019, 4:44 PM EST
assertEquals(2019, dt.yearInt)
}
@Test
fun dateTime_shouldGiveTheCorrectMonthWhenGivenUnixTimestamp() {
val dt = DateTime.fromUnix(1563482699) //July 18, 2019, 4:44 PM EST
assertEquals(Month.July, dt.month)
}
The first test finds that the year is actually 1970, and the second finds the month is January. Curiously, there's nothing wrong with the Unix Timestamp inside of the DateTime.
I have just changed the license of Klock from MIT/APACHE2 to Public Domain, just in case it would help to grab some code without any kind of worries to shape any date & time library from Kotlin or other people.
Regarding to Klock: I designed Klock to be as allocation-free as possible (inline classes), thinking that the Kotlin way would be to offer per-platform wrappings around native APIs that would incur in allocations. I designed klock to be used in korge a game engine, in which case each allocation counts.
The initial Kotlin steps has been to preview a Duration
inline class:
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.time/-duration/index.html
also wrapping a Double
that wouldn't incur in any allocation on any taget including JS. That would fit the klock needs and would be mostly compatible.
Depending on the direction of the official Kotlin library I would take one direction or another.
Once Duration
is release as stable I will make a typealias
for the TimeSpan
class and will provide extension methods/properties to fill the gaps and keep it as source-compatible as possible and will provide @Deprecated
replaceWith if it helps.
Depending on the decisions of the DateTime
/Instant
part I will do the same with DateTime, or will keep it as separate but will provide methods to convert from/between the official Instant class.
I plan to keep working on Klock as long as there are gaps or missing functionality not offered from the official API, and cover them here trying always to be as typealias friendly as possible to not duplicate types, but always providing the allocation-free classes this offers.
If you have thoughts/ideas/feedback on this, please let me know here.
Hi,
when is support for Kotlin 1.3.50 planned?
Hello, what time could update 1.5.0 to https://dl.bintray.com/korlibs/korlibs for mingwx64
Hello there,
in https://github.com/mschirmacher/wtf i prepared a small testcase to demonstrate the problem.
Long story short: assertTrue(DateTime.nowUnixLong() is Long)
fails because klock brings its own kotlin.js
hence we end up with two kotlin dependencies in the project and two declarations of Long
.
You may find more information and discussion abput the problem mostly at the end of this
thread on slack: https://kotlinlang.slack.com/archives/C0B8L3U69/p1574427184210500
Tried following the existing closed issue,#16 (comment), BUT NEGATIVE.
I am using klock for one of my multiplatform project and I ended up with this issue
SharedCode/src/commonMain/kotlin/common.kt: (3, 25): Unresolved reference: DateTime
My gradle versions:
Gradle : 5.3.1
Kotlin: 1.3.20
klock: 1.4.0
My gradle files looks as below:
kotlin {
targets {
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
fromPreset(iOSTarget, 'iOS') {
compilations.main.outputKinds('FRAMEWORK')
}
fromPreset(presets.jvm, 'android')
}
sourceSets {
commonMain {
dependencies {
implementation "com.soywiz:klock-metadata:${klockVersion}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
}
}
commonTest {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-test-common:${kotlin_version}"
implementation "org.jetbrains.kotlin:kotlin-test-annotations-common:${kotlin_version}"
}
}
androidMain {
dependencies {
implementation "com.soywiz:klock-android:${klockVersion}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${kotlin_version}"
}
}
jvmTest {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
implementation "org.jetbrains.kotlin:kotlin-test-junit:${kotlin_version}"
}
}
iosMain {
dependencies{
implementation 'com.soywiz:klock-iosarm32:1.2.0'
implementation 'com.soywiz:klock-iosarm64:1.2.0'
implementation 'com.soywiz:klock-iosx64:1.2.0'
}
}
iosTest {
}
iosArm64Main {
dependsOn iosMain
}
iosX64Main {
dependsOn iosMain
}
}
}
We experienced a bug using klock wherein our framework, which uses klock, would hang up on an Android application, without any logs or thrown errors.
This was due to us only importing klock on commonMain
, as such :
kotlin {
sourceSets {
commonMain {
dependencies {
implementation "com.soywiz.korlibs.klock:klock:$klockVersion" // Common
}
}
}
}
This was fixed by following README and also adding Android/JVM specific dependency :
dependencies {
implementation "com.soywiz.korlibs.klock:klock-jvm:$klockVersion"
}
This bug was our fault, however it would be expected that klock would throw an exception or log an error message if this dependency is not explicitly included.
Hey,
is there any reason for the minSDK to be 18 for this specific lib ?
From perusing the source I did not find any, and the minSdk is set by the plugin across all your libraries on https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin/blob/c163e5dcc870e79dae11620442cb73827b48c705/src/main/kotlin/com/soywiz/korlibs/targets/Android.kt#L13
We have a minSdk 16 requirement, want to confirm if it's fine to use this lib :)
For more convenient behavior OffsetDateTime need to implement these methods.
I have spent the past few days figuring out how to use Klock.
Documentation varies from site to site and now i'm using the approach in the README:
https://github.com/korlibs/klock/blob/master/README.md
However when compiling the project I get these errors relating to my build types:
ERROR: Unable to resolve dependency for ':shared@debug/compileClasspath': Could not resolve com.soywiz.korlibs.klock:klock:1.5.0.
Show Details
Affected Modules: shared
ERROR: Unable to resolve dependency for ':shared@release/compileClasspath': Could not resolve com.soywiz.korlibs.klock:klock:1.5.0.
Show Details
Affected Modules: shared
Hi there! I had klock working with Kotlin 1.3.11, but now with 1.3.20, I'm getting build errors. I'm assuming (correct me if I'm wrong) that's because something about binarty compatibility changed with 1.3.20. If that make sense, could you do another release for Kotlin 1.3.20? Thanks! (specifically trying to build for iOS arm64/x64)
Hello, thanks for developing this amazing library..
The documentation of "Usage with gradle" from https://korlibs.soywiz.com/klock/ and https://github.com/korlibs/klock/blob/master/README.md is wrong and confusing. Please correct it:
dependencies {
// For multiplatform projects, since klock is published without metadata
implementation "com.soywiz:klock-metadata:$klockVersion" // Common
implementation "com.soywiz:klock-jvm:$klockVersion" // JVM
implementation "com.soywiz:klock-js:$klockVersion" // JavaScript
implementation "com.soywiz:klock-android:$klockVersion" // Android
implementation "com.soywiz:klock-iosx64:$libraryVersion" // iOS Simulator
implementation "com.soywiz:klock-iosarm32:$libraryVersion" // Older iOS 32-bit devices
implementation "com.soywiz:klock-iosarm64:$libraryVersion" // Newer iOS 64-bit devices
implementation "com.soywiz:klock-macosx64:$libraryVersion" // MacOS
implementation "com.soywiz:klock-linuxx64:$libraryVersion" // Linux x64
implementation "com.soywiz:klock-mingwx64:$libraryVersion" // Windows x64
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.