Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ val size: UInt = interval.size // 10
```

This protects against overflows (e.g. if `size > Int.MAX_VALUE`) but also offers better semantics.
For example, you can create intervals for [kotlinx datetime](https://github.com/Kotlin/kotlinx-datetime) `Instant` values which are a `Duration` apart.
For example, this library supports [kotlinx datetime](https://github.com/Kotlin/kotlinx-datetime) `Instant` values which are a `Duration` apart.

```kotlin
val now = Clock.System.now()
val interval: InstantInterval = interval( now, now + 100.seconds )
val areIncluded = now + 50.seconds in interval // true
val size: Duration = interval.size // 100 seconds
```

## Interval Types

This library includes a generic base class `Interval<T, TSize>` which can be used to create intervals for any type.
To achieve this, it directs type operations to `IntervalTypeOperations` which the constructor takes as a parameter.

The following interval types are included by default:
The following interval types are included in `io.github.whathecode.kotlinx.interval:kotlinx-interval` on Maven:

| Type | Values (`T`) | Distances (`TSize`) |
|:----------------:|:------------:|:-------------------:|
Expand All @@ -38,4 +45,8 @@ The following interval types are included by default:
| `UShortInterval` | `UShort` | `UShort` |
| `UIntInterval` | `UInt` | `UInt` |
| `ULongInterval` | `ULong` | `ULong` |
| `CharInterval` | `Char` | `UShort` |
| `CharInterval` | `Char` | `UShort` |

### Date/time intervals
Date/time intervals are implemented as `InstantInterval` using the [kotlinx datetime](https://github.com/Kotlin/kotlinx-datetime) library.
Since you may not always want to pull in this dependency, this class is published separately in `io.github.whathecode.kotlinx.interval:kotlinx-interval-datetime`.
128 changes: 7 additions & 121 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,66 +1,7 @@
import java.io.FileInputStream
import java.util.Properties
import org.gradle.jvm.tasks.Jar
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.gradle.DokkaTask


plugins {
kotlin("multiplatform") version "1.6.20"
`maven-publish`
signing
id("org.jetbrains.dokka") version "1.6.21"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}

group = "io.github.whathecode.kotlinx.interval"
version = "1.0.0-alpha.2"

repositories {
mavenCentral()
gradlePluginPortal()
}

kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js(BOTH) {
browser { }
}
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}


sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
}


// Publish configuration.
// For signing and publishing to work, a 'publish.properties' file needs to be added to the root containing:
// The OpenPGP credentials to sign all artifacts:
Expand All @@ -69,70 +10,13 @@ kotlin {
// A username and password to upload artifacts to the Sonatype repository:
// > repository.username=<SONATYPE USERNAME>
// > repository.password=<SONATYPE PASSWORD>
val publishProperties = Properties()
val publishProperties = java.util.Properties()
val publishPropertiesFile = File("publish.properties")
if (publishPropertiesFile.exists()) {
publishProperties.load(FileInputStream(publishPropertiesFile))
}
val dokkaJvmJavadoc by tasks.creating(DokkaTask::class) {
dokkaSourceSets {
register("jvm") {
platform.set(Platform.jvm)
sourceRoots.from(kotlin.sourceSets.getByName("jvmMain").kotlin.srcDirs)
}
}
}
val javadocJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Create javadoc jar using Dokka"
archiveClassifier.set("javadoc")
from(dokkaJvmJavadoc)
}
publishing {
repositories {
maven {
name = "local"
url = uri("$buildDir/repo")
}
}
publications.filterIsInstance<MavenPublication>().forEach {
if (it.name == "jvm") {
it.artifact(javadocJar)
}
it.pom {
name.set("kotlinx.interval")
description.set("Kotlin multiplatform bounded open/closed generic intervals.")
url.set("https://github.com/Whathecode/kotlinx.interval")
licenses {
license {
name.set("The Apache Licence, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("Whathecode")
name.set("Steven Jeuris")
email.set("steven.jeuris@gmail.com")
}
}
scm {
connection.set("scm:git:git://github.com/Whathecode/kotlinx.interval.git")
developerConnection.set("scm:git:ssh://github.com/Whathecode/carp.core-kotlin.git")
url.set("https://github.com/Whathecode/kotlinx.interval")
}
}
}
}
signing {
val signingKeyFile = publishProperties["signing.keyFile"] as? String
if (signingKeyFile != null) {
val signingKey = File(signingKeyFile).readText()
val signingPassword = publishProperties["signing.password"] as? String
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}
publishProperties.load(java.io.FileInputStream(publishPropertiesFile))
}
group = "io.github.whathecode.kotlinx.interval"
version = "1.0.0-alpha.3"
nexusPublishing {
repositories {
sonatype {
Expand All @@ -143,10 +27,12 @@ nexusPublishing {
}
}
}
val setSnapshotVersion by tasks.creating {
val setSnapshotVersion: Task by tasks.creating {
doFirst {
val versionSplit = version.toString().split("-")
val snapshotVersion = "${versionSplit[0]}-SNAPSHOT"
version = snapshotVersion

rootProject.subprojects.forEach { it.version = snapshotVersion }
}
}
13 changes: 13 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.6.21")
}
Empty file added buildSrc/settings.gradle.kts
Empty file.
124 changes: 124 additions & 0 deletions buildSrc/src/main/kotlin/interval.library-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import java.io.FileInputStream
import java.util.Properties
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.gradle.DokkaTask


plugins {
kotlin("multiplatform")
id("org.jetbrains.dokka")
`maven-publish`
signing
}

repositories {
mavenCentral()
}


kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js(BOTH) {
browser { }
}
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}


sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
}


// Documentation.
val dokkaJvmJavadoc by tasks.creating(DokkaTask::class) {
dokkaSourceSets {
register("jvm") {
platform.set(Platform.jvm)
sourceRoots.from(kotlin.sourceSets.getByName("jvmMain").kotlin.srcDirs)
}
}
}
val javadocJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Create javadoc jar using Dokka"
archiveClassifier.set("javadoc")
from(dokkaJvmJavadoc)
}


// Publish configuration.
val publishProperties = Properties()
val publishPropertiesFile = File("publish.properties")
if (publishPropertiesFile.exists()) {
publishProperties.load(FileInputStream(publishPropertiesFile))
}
publishing {
repositories {
maven {
name = "local"
url = uri("$buildDir/repo")
}
}
publications.filterIsInstance<MavenPublication>().forEach {
if (it.name == "jvm") {
it.artifact(javadocJar)
}
it.pom {
url.set("https://github.com/Whathecode/kotlinx.interval")
licenses {
license {
name.set("The Apache Licence, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("Whathecode")
name.set("Steven Jeuris")
email.set("steven.jeuris@gmail.com")
}
}
scm {
connection.set("scm:git:git://github.com/Whathecode/kotlinx.interval.git")
developerConnection.set("scm:git:ssh://github.com/Whathecode/carp.core-kotlin.git")
url.set("https://github.com/Whathecode/kotlinx.interval")
}
}
}
}
signing {
val signingKeyFile = publishProperties["signing.keyFile"] as? String
if (signingKeyFile != null) {
val signingKey = File(signingKeyFile).readText()
val signingPassword = publishProperties["signing.password"] as? String
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}
}
5 changes: 5 additions & 0 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==

"@js-joda/core@3.2.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@js-joda/core/-/core-3.2.0.tgz#3e61e21b7b2b8a6be746df1335cf91d70db2a273"
integrity sha512-PMqgJ0sw5B7FKb2d5bWYIoxjri+QlW/Pys7+Rw82jSH0QN3rB05jZ/VrrsUdh1w4+i2kw9JOejXGq/KhDOX7Kg==

"@types/component-emitter@^1.2.10":
version "1.2.11"
resolved "https://registry.yarnpkg.com/@types/component-emitter/-/component-emitter-1.2.11.tgz#50d47d42b347253817a39709fef03ce66a108506"
Expand Down
31 changes: 31 additions & 0 deletions kotlinx.interval.datetime/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
group = rootProject.group
version = rootProject.version

plugins {
id( "interval.library-conventions" )
}

publishing {
publications.filterIsInstance<MavenPublication>().forEach {
it.pom {
name.set("kotlinx-interval-datetime")
description.set("Kotlin multiplatform bounded open/closed date/time intervals.")
}
}
}

kotlin {
sourceSets {
commonMain {
dependencies {
api(project(":kotlinx-interval"))
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
}
}
commonTest {
dependencies {
implementation(project(":kotlinx-interval-test"))
}
}
}
}
Loading