Skip to content

Commit 59c50b2

Browse files
authored
Merge pull request #18 from Whathecode/develop
Release 1.0.0-alpha.3 (attempt 3)
2 parents e243a90 + 2e062f5 commit 59c50b2

File tree

25 files changed

+382
-128
lines changed

25 files changed

+382
-128
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ val size: UInt = interval.size // 10
1717
```
1818

1919
This protects against overflows (e.g. if `size > Int.MAX_VALUE`) but also offers better semantics.
20-
For example, you can create intervals for [kotlinx datetime](https://github.com/Kotlin/kotlinx-datetime) `Instant` values which are a `Duration` apart.
20+
For example, this library supports [kotlinx datetime](https://github.com/Kotlin/kotlinx-datetime) `Instant` values which are a `Duration` apart.
21+
22+
```kotlin
23+
val now = Clock.System.now()
24+
val interval: InstantInterval = interval( now, now + 100.seconds )
25+
val areIncluded = now + 50.seconds in interval // true
26+
val size: Duration = interval.size // 100 seconds
27+
```
2128

2229
## Interval Types
2330

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

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

2936
| Type | Values (`T`) | Distances (`TSize`) |
3037
|:----------------:|:------------:|:-------------------:|
@@ -38,4 +45,8 @@ The following interval types are included by default:
3845
| `UShortInterval` | `UShort` | `UShort` |
3946
| `UIntInterval` | `UInt` | `UInt` |
4047
| `ULongInterval` | `ULong` | `ULong` |
41-
| `CharInterval` | `Char` | `UShort` |
48+
| `CharInterval` | `Char` | `UShort` |
49+
50+
### Date/time intervals
51+
Date/time intervals are implemented as `InstantInterval` using the [kotlinx datetime](https://github.com/Kotlin/kotlinx-datetime) library.
52+
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`.

build.gradle.kts

Lines changed: 7 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,7 @@
1-
import java.io.FileInputStream
2-
import java.util.Properties
3-
import org.gradle.jvm.tasks.Jar
4-
import org.jetbrains.dokka.Platform
5-
import org.jetbrains.dokka.gradle.DokkaTask
6-
7-
81
plugins {
9-
kotlin("multiplatform") version "1.6.20"
10-
`maven-publish`
11-
signing
12-
id("org.jetbrains.dokka") version "1.6.21"
132
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
143
}
154

16-
group = "io.github.whathecode.kotlinx.interval"
17-
version = "1.0.0-alpha.2"
18-
19-
repositories {
20-
mavenCentral()
21-
gradlePluginPortal()
22-
}
23-
24-
kotlin {
25-
jvm {
26-
compilations.all {
27-
kotlinOptions.jvmTarget = "1.8"
28-
}
29-
withJava()
30-
testRuns["test"].executionTask.configure {
31-
useJUnitPlatform()
32-
}
33-
}
34-
js(BOTH) {
35-
browser { }
36-
}
37-
val hostOs = System.getProperty("os.name")
38-
val isMingwX64 = hostOs.startsWith("Windows")
39-
val nativeTarget = when {
40-
hostOs == "Mac OS X" -> macosX64("native")
41-
hostOs == "Linux" -> linuxX64("native")
42-
isMingwX64 -> mingwX64("native")
43-
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
44-
}
45-
46-
47-
sourceSets {
48-
val commonMain by getting
49-
val commonTest by getting {
50-
dependencies {
51-
implementation(kotlin("test"))
52-
}
53-
}
54-
val jvmMain by getting
55-
val jvmTest by getting
56-
val jsMain by getting
57-
val jsTest by getting
58-
val nativeMain by getting
59-
val nativeTest by getting
60-
}
61-
}
62-
63-
645
// Publish configuration.
656
// For signing and publishing to work, a 'publish.properties' file needs to be added to the root containing:
667
// The OpenPGP credentials to sign all artifacts:
@@ -69,70 +10,13 @@ kotlin {
6910
// A username and password to upload artifacts to the Sonatype repository:
7011
// > repository.username=<SONATYPE USERNAME>
7112
// > repository.password=<SONATYPE PASSWORD>
72-
val publishProperties = Properties()
13+
val publishProperties = java.util.Properties()
7314
val publishPropertiesFile = File("publish.properties")
7415
if (publishPropertiesFile.exists()) {
75-
publishProperties.load(FileInputStream(publishPropertiesFile))
76-
}
77-
val dokkaJvmJavadoc by tasks.creating(DokkaTask::class) {
78-
dokkaSourceSets {
79-
register("jvm") {
80-
platform.set(Platform.jvm)
81-
sourceRoots.from(kotlin.sourceSets.getByName("jvmMain").kotlin.srcDirs)
82-
}
83-
}
84-
}
85-
val javadocJar by tasks.creating(Jar::class) {
86-
group = JavaBasePlugin.DOCUMENTATION_GROUP
87-
description = "Create javadoc jar using Dokka"
88-
archiveClassifier.set("javadoc")
89-
from(dokkaJvmJavadoc)
90-
}
91-
publishing {
92-
repositories {
93-
maven {
94-
name = "local"
95-
url = uri("$buildDir/repo")
96-
}
97-
}
98-
publications.filterIsInstance<MavenPublication>().forEach {
99-
if (it.name == "jvm") {
100-
it.artifact(javadocJar)
101-
}
102-
it.pom {
103-
name.set("kotlinx.interval")
104-
description.set("Kotlin multiplatform bounded open/closed generic intervals.")
105-
url.set("https://github.com/Whathecode/kotlinx.interval")
106-
licenses {
107-
license {
108-
name.set("The Apache Licence, Version 2.0")
109-
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
110-
}
111-
}
112-
developers {
113-
developer {
114-
id.set("Whathecode")
115-
name.set("Steven Jeuris")
116-
email.set("[email protected]")
117-
}
118-
}
119-
scm {
120-
connection.set("scm:git:git://github.com/Whathecode/kotlinx.interval.git")
121-
developerConnection.set("scm:git:ssh://github.com/Whathecode/carp.core-kotlin.git")
122-
url.set("https://github.com/Whathecode/kotlinx.interval")
123-
}
124-
}
125-
}
126-
}
127-
signing {
128-
val signingKeyFile = publishProperties["signing.keyFile"] as? String
129-
if (signingKeyFile != null) {
130-
val signingKey = File(signingKeyFile).readText()
131-
val signingPassword = publishProperties["signing.password"] as? String
132-
useInMemoryPgpKeys(signingKey, signingPassword)
133-
sign(publishing.publications)
134-
}
16+
publishProperties.load(java.io.FileInputStream(publishPropertiesFile))
13517
}
18+
group = "io.github.whathecode.kotlinx.interval"
19+
version = "1.0.0-alpha.3"
13620
nexusPublishing {
13721
repositories {
13822
sonatype {
@@ -143,10 +27,12 @@ nexusPublishing {
14327
}
14428
}
14529
}
146-
val setSnapshotVersion by tasks.creating {
30+
val setSnapshotVersion: Task by tasks.creating {
14731
doFirst {
14832
val versionSplit = version.toString().split("-")
14933
val snapshotVersion = "${versionSplit[0]}-SNAPSHOT"
15034
version = snapshotVersion
35+
36+
rootProject.subprojects.forEach { it.version = snapshotVersion }
15137
}
15238
}

buildSrc/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
gradlePluginPortal()
8+
}
9+
10+
dependencies {
11+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20")
12+
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.6.21")
13+
}

buildSrc/settings.gradle.kts

Whitespace-only changes.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import java.io.FileInputStream
2+
import java.util.Properties
3+
import org.jetbrains.dokka.Platform
4+
import org.jetbrains.dokka.gradle.DokkaTask
5+
6+
7+
plugins {
8+
kotlin("multiplatform")
9+
id("org.jetbrains.dokka")
10+
`maven-publish`
11+
signing
12+
}
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
19+
kotlin {
20+
jvm {
21+
compilations.all {
22+
kotlinOptions.jvmTarget = "1.8"
23+
}
24+
withJava()
25+
testRuns["test"].executionTask.configure {
26+
useJUnitPlatform()
27+
}
28+
}
29+
js(BOTH) {
30+
browser { }
31+
}
32+
val hostOs = System.getProperty("os.name")
33+
val isMingwX64 = hostOs.startsWith("Windows")
34+
val nativeTarget = when {
35+
hostOs == "Mac OS X" -> macosX64("native")
36+
hostOs == "Linux" -> linuxX64("native")
37+
isMingwX64 -> mingwX64("native")
38+
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
39+
}
40+
41+
42+
sourceSets {
43+
val commonMain by getting
44+
val commonTest by getting {
45+
dependencies {
46+
implementation(kotlin("test"))
47+
}
48+
}
49+
val jvmMain by getting
50+
val jvmTest by getting
51+
val jsMain by getting
52+
val jsTest by getting
53+
val nativeMain by getting
54+
val nativeTest by getting
55+
}
56+
}
57+
58+
59+
// Documentation.
60+
val dokkaJvmJavadoc by tasks.creating(DokkaTask::class) {
61+
dokkaSourceSets {
62+
register("jvm") {
63+
platform.set(Platform.jvm)
64+
sourceRoots.from(kotlin.sourceSets.getByName("jvmMain").kotlin.srcDirs)
65+
}
66+
}
67+
}
68+
val javadocJar by tasks.creating(Jar::class) {
69+
group = JavaBasePlugin.DOCUMENTATION_GROUP
70+
description = "Create javadoc jar using Dokka"
71+
archiveClassifier.set("javadoc")
72+
from(dokkaJvmJavadoc)
73+
}
74+
75+
76+
// Publish configuration.
77+
val publishProperties = Properties()
78+
val publishPropertiesFile = File("publish.properties")
79+
if (publishPropertiesFile.exists()) {
80+
publishProperties.load(FileInputStream(publishPropertiesFile))
81+
}
82+
publishing {
83+
repositories {
84+
maven {
85+
name = "local"
86+
url = uri("$buildDir/repo")
87+
}
88+
}
89+
publications.filterIsInstance<MavenPublication>().forEach {
90+
if (it.name == "jvm") {
91+
it.artifact(javadocJar)
92+
}
93+
it.pom {
94+
url.set("https://github.com/Whathecode/kotlinx.interval")
95+
licenses {
96+
license {
97+
name.set("The Apache Licence, Version 2.0")
98+
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
99+
}
100+
}
101+
developers {
102+
developer {
103+
id.set("Whathecode")
104+
name.set("Steven Jeuris")
105+
email.set("[email protected]")
106+
}
107+
}
108+
scm {
109+
connection.set("scm:git:git://github.com/Whathecode/kotlinx.interval.git")
110+
developerConnection.set("scm:git:ssh://github.com/Whathecode/carp.core-kotlin.git")
111+
url.set("https://github.com/Whathecode/kotlinx.interval")
112+
}
113+
}
114+
}
115+
}
116+
signing {
117+
val signingKeyFile = publishProperties["signing.keyFile"] as? String
118+
if (signingKeyFile != null) {
119+
val signingKey = File(signingKeyFile).readText()
120+
val signingPassword = publishProperties["signing.password"] as? String
121+
useInMemoryPgpKeys(signingKey, signingPassword)
122+
sign(publishing.publications)
123+
}
124+
}

kotlin-js-store/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
88
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==
99

10+
"@js-joda/[email protected]":
11+
version "3.2.0"
12+
resolved "https://registry.yarnpkg.com/@js-joda/core/-/core-3.2.0.tgz#3e61e21b7b2b8a6be746df1335cf91d70db2a273"
13+
integrity sha512-PMqgJ0sw5B7FKb2d5bWYIoxjri+QlW/Pys7+Rw82jSH0QN3rB05jZ/VrrsUdh1w4+i2kw9JOejXGq/KhDOX7Kg==
14+
1015
"@types/component-emitter@^1.2.10":
1116
version "1.2.11"
1217
resolved "https://registry.yarnpkg.com/@types/component-emitter/-/component-emitter-1.2.11.tgz#50d47d42b347253817a39709fef03ce66a108506"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
group = rootProject.group
2+
version = rootProject.version
3+
4+
plugins {
5+
id( "interval.library-conventions" )
6+
}
7+
8+
publishing {
9+
publications.filterIsInstance<MavenPublication>().forEach {
10+
it.pom {
11+
name.set("kotlinx-interval-datetime")
12+
description.set("Kotlin multiplatform bounded open/closed date/time intervals.")
13+
}
14+
}
15+
}
16+
17+
kotlin {
18+
sourceSets {
19+
commonMain {
20+
dependencies {
21+
api(project(":kotlinx-interval"))
22+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
23+
}
24+
}
25+
commonTest {
26+
dependencies {
27+
implementation(project(":kotlinx-interval-test"))
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)