Skip to content

Commit c665c15

Browse files
committed
Move InstantInterval to main library; update Kotlin 2.3.10, datetime 0.7.1
Starting from Kotlin 2.1.20, `Instant` from kotlinx.datetime was introduced in the Kotlin base library. It has been removed in kotlinx.datetime 0.7.0.
1 parent 550756e commit c665c15

11 files changed

Lines changed: 1155 additions & 673 deletions

File tree

README.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ val shifted = interval shr 10u // Shifted right by 10: [10, 20)
1818
```
1919

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

2323
```kotlin
2424
val now = Clock.System.now()
@@ -120,20 +120,17 @@ To achieve this, it directs type operations to `IntervalTypeOperations` which th
120120

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

123-
| Type | Values (`T`) | Distances (`TSize`) |
124-
|:----------------:|:------------:|:-------------------:|
125-
| `ByteInterval` | `Byte` | `UByte` |
126-
| `ShortInterval` | `Short` | `UShort` |
127-
| `IntInterval` | `Int` | `UInt` |
128-
| `LongInterval` | `Long` | `ULong` |
129-
| `FloatInterval` | `Float` | `Double` |
130-
| `DoubleInterval` | `Double` | `Double` |
131-
| `UByteInterval` | `UByte` | `UByte` |
132-
| `UShortInterval` | `UShort` | `UShort` |
133-
| `UIntInterval` | `UInt` | `UInt` |
134-
| `ULongInterval` | `ULong` | `ULong` |
135-
| `CharInterval` | `Char` | `UShort` |
136-
137-
### Date/time intervals
138-
Date/time intervals are implemented as `InstantInterval` using the [kotlinx datetime](https://github.com/Kotlin/kotlinx-datetime) library.
139-
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`.
123+
| Type | Values (`T`) | Distances (`TSize`) |
124+
|:------------------:|:------------:|:-------------------:|
125+
| `ByteInterval` | `Byte` | `UByte` |
126+
| `ShortInterval` | `Short` | `UShort` |
127+
| `IntInterval` | `Int` | `UInt` |
128+
| `LongInterval` | `Long` | `ULong` |
129+
| `FloatInterval` | `Float` | `Double` |
130+
| `DoubleInterval` | `Double` | `Double` |
131+
| `UByteInterval` | `UByte` | `UByte` |
132+
| `UShortInterval` | `UShort` | `UShort` |
133+
| `UIntInterval` | `UInt` | `UInt` |
134+
| `ULongInterval` | `ULong` | `ULong` |
135+
| `CharInterval` | `Char` | `UShort` |
136+
| `InstantInterval` | `Instant` | `Duration` |

build-logic/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ repositories {
88
}
99

1010
dependencies {
11-
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.21")
11+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.3.10")
1212
implementation("org.jetbrains.dokka:dokka-gradle-plugin:2.0.0")
1313
}

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if (publishPropertiesFile.exists()) {
2121
publishProperties.load(java.io.FileInputStream(publishPropertiesFile))
2222
}
2323
group = "io.github.whathecode.kotlinx.interval"
24-
version = "2.1.0"
24+
version = "2.2.0"
2525
if (properties.containsKey("snapshot"))
2626
{
2727
val versionSplit = version.toString().split("-")

kotlin-js-store/yarn.lock

Lines changed: 1113 additions & 628 deletions
Large diffs are not rendered by default.

kotlinx.interval.datetime/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ kotlin {
1919
commonMain {
2020
dependencies {
2121
api(project(":kotlinx-interval"))
22-
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.2")
22+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")
2323
}
2424
}
2525
commonTest {

kotlinx.interval.datetime/src/commonTest/kotlin/Readme.kt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,18 @@
22

33
package io.github.whathecode.kotlinx.interval.datetime
44

5+
import io.github.whathecode.kotlinx.interval.InstantInterval
56
import io.github.whathecode.kotlinx.interval.IntInterval
67
import io.github.whathecode.kotlinx.interval.interval
7-
import kotlinx.datetime.Clock
8-
import kotlinx.datetime.Instant
98
import kotlinx.datetime.LocalDateTime
109
import kotlinx.datetime.TimeZone
1110
import kotlinx.datetime.toInstant
1211
import kotlin.test.*
13-
import kotlin.time.Duration
14-
import kotlin.time.Duration.Companion.hours
15-
import kotlin.time.Duration.Companion.seconds
12+
import kotlin.time.Instant
1613

1714

1815
class Readme
1916
{
20-
@Test
21-
fun introduction_instant_interval_example()
22-
{
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-
val shifted = interval shr 24.hours // 100 seconds 24 hours from now
28-
}
29-
3017
@Test
3118
fun introduction_common_math()
3219
{

kotlinx.interval.datetime/src/commonMain/kotlin/InstantInterval.kt renamed to kotlinx.interval/src/commonMain/kotlin/InstantInterval.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package io.github.whathecode.kotlinx.interval.datetime
1+
package io.github.whathecode.kotlinx.interval
22

33
import io.github.whathecode.kotlinx.interval.Interval
44
import io.github.whathecode.kotlinx.interval.IntervalTypeOperations
5-
import kotlinx.datetime.Instant
65
import kotlin.math.absoluteValue
76
import kotlin.time.Duration
7+
import kotlin.time.Instant
88

99

1010
/**

kotlinx.interval.datetime/src/commonMain/kotlin/DateTimeTypeOperations.kt renamed to kotlinx.interval/src/commonMain/kotlin/TimeTypeOperations.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package io.github.whathecode.kotlinx.interval.datetime
1+
package io.github.whathecode.kotlinx.interval
22

3-
import io.github.whathecode.kotlinx.interval.TypeOperations
4-
import kotlinx.datetime.Instant
53
import kotlin.time.Duration
64
import kotlin.time.Duration.Companion.milliseconds
75
import kotlin.time.DurationUnit
6+
import kotlin.time.Instant
87

98

109
internal object InstantOperations : TypeOperations<Instant>

kotlinx.interval.datetime/src/commonTest/kotlin/InstantIntervalTest.kt renamed to kotlinx.interval/src/commonTest/kotlin/InstantIntervalTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package io.github.whathecode.kotlinx.interval.datetime
1+
package io.github.whathecode.kotlinx.interval
22

33
import io.github.whathecode.kotlinx.interval.test.IntervalTest
4-
import kotlinx.datetime.Instant
54
import kotlin.time.Duration
5+
import kotlin.time.Instant
66

77

88
private val a = Instant.fromEpochSeconds( 0, 50 )

kotlinx.interval/src/commonTest/kotlin/Readme.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
package io.github.whathecode.kotlinx.interval
44

55
import kotlin.test.*
6+
import kotlin.time.Clock
7+
import kotlin.time.Duration
8+
import kotlin.time.Duration.Companion.hours
9+
import kotlin.time.Duration.Companion.seconds
610

711

812
class Readme
@@ -28,4 +32,14 @@ class Readme
2832
val unite = splitInTwo + interval( 10, 90 ) // Interval: [0, 100]
2933
val backToStart = start == unite // true
3034
}
35+
36+
@Test
37+
fun introduction_instant_interval_example()
38+
{
39+
val now = Clock.System.now()
40+
val interval: InstantInterval = interval( now, now + 100.seconds )
41+
val areIncluded = now + 50.seconds in interval // true
42+
val size: Duration = interval.size // 100 seconds
43+
val shifted = interval shr 24.hours // 100 seconds 24 hours from now
44+
}
3145
}

0 commit comments

Comments
 (0)