Skip to content

Commit 661ae98

Browse files
authored
Enable strict API mode (#100)
1 parent 93c9150 commit 661ae98

33 files changed

+189
-188
lines changed

core/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ val JDK_8: String by project
2222
val serializationVersion: String by project
2323

2424
kotlin {
25+
explicitApi()
26+
2527
infra {
2628
target("linuxX64")
2729
target("mingwX64")

core/common/src/DateTimePeriod.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ import kotlinx.serialization.Serializable
1414

1515
@Serializable(with = DateTimePeriodIso8601Serializer::class)
1616
// TODO: could be error-prone without explicitly named params
17-
sealed class DateTimePeriod {
17+
public sealed class DateTimePeriod {
1818
internal abstract val totalMonths: Int
19-
abstract val days: Int
19+
public abstract val days: Int
2020
internal abstract val totalNanoseconds: Long
2121

22-
val years: Int get() = totalMonths / 12
23-
val months: Int get() = totalMonths % 12
24-
open val hours: Int get() = (totalNanoseconds / 3_600_000_000_000).toInt()
25-
open val minutes: Int get() = ((totalNanoseconds % 3_600_000_000_000) / 60_000_000_000).toInt()
26-
open val seconds: Int get() = ((totalNanoseconds % 60_000_000_000) / NANOS_PER_ONE).toInt()
27-
open val nanoseconds: Int get() = (totalNanoseconds % NANOS_PER_ONE).toInt()
22+
public val years: Int get() = totalMonths / 12
23+
public val months: Int get() = totalMonths % 12
24+
public open val hours: Int get() = (totalNanoseconds / 3_600_000_000_000).toInt()
25+
public open val minutes: Int get() = ((totalNanoseconds % 3_600_000_000_000) / 60_000_000_000).toInt()
26+
public open val seconds: Int get() = ((totalNanoseconds % 60_000_000_000) / NANOS_PER_ONE).toInt()
27+
public open val nanoseconds: Int get() = (totalNanoseconds % NANOS_PER_ONE).toInt()
2828

2929
private fun allNonpositive() =
3030
totalMonths <= 0 && days <= 0 && totalNanoseconds <= 0 && (totalMonths or days != 0 || totalNanoseconds != 0L)
@@ -70,8 +70,8 @@ sealed class DateTimePeriod {
7070
return result
7171
}
7272

73-
companion object {
74-
fun parse(text: String): DateTimePeriod {
73+
public companion object {
74+
public fun parse(text: String): DateTimePeriod {
7575
fun parseException(message: String, position: Int): Nothing =
7676
throw DateTimeFormatException("Parse error at char $position: $message")
7777
val START = 0
@@ -238,20 +238,20 @@ sealed class DateTimePeriod {
238238
public fun String.toDateTimePeriod(): DateTimePeriod = DateTimePeriod.parse(this)
239239

240240
@Serializable(with = DatePeriodIso8601Serializer::class)
241-
class DatePeriod internal constructor(
241+
public class DatePeriod internal constructor(
242242
internal override val totalMonths: Int,
243243
override val days: Int,
244244
) : DateTimePeriod() {
245-
constructor(years: Int = 0, months: Int = 0, days: Int = 0): this(totalMonths(years, months), days)
245+
public constructor(years: Int = 0, months: Int = 0, days: Int = 0): this(totalMonths(years, months), days)
246246
// avoiding excessive computations
247247
override val hours: Int get() = 0
248248
override val minutes: Int get() = 0
249249
override val seconds: Int get() = 0
250250
override val nanoseconds: Int get() = 0
251251
internal override val totalNanoseconds: Long get() = 0
252252

253-
companion object {
254-
fun parse(text: String): DatePeriod =
253+
public companion object {
254+
public fun parse(text: String): DatePeriod =
255255
when (val period = DateTimePeriod.parse(text)) {
256256
is DatePeriod -> period
257257
else -> throw DateTimeFormatException("Period $period (parsed from string $text) is not date-based")
@@ -296,7 +296,7 @@ internal fun buildDateTimePeriod(totalMonths: Int = 0, days: Int = 0, totalNanos
296296
else
297297
DatePeriod(totalMonths, days)
298298

299-
fun DateTimePeriod(
299+
public fun DateTimePeriod(
300300
years: Int = 0,
301301
months: Int = 0,
302302
days: Int = 0,
@@ -308,15 +308,15 @@ fun DateTimePeriod(
308308
totalNanoseconds(hours, minutes, seconds, nanoseconds))
309309

310310
@OptIn(ExperimentalTime::class)
311-
fun Duration.toDateTimePeriod(): DateTimePeriod = buildDateTimePeriod(totalNanoseconds = toLongNanoseconds())
311+
public fun Duration.toDateTimePeriod(): DateTimePeriod = buildDateTimePeriod(totalNanoseconds = toLongNanoseconds())
312312

313-
operator fun DateTimePeriod.plus(other: DateTimePeriod): DateTimePeriod = buildDateTimePeriod(
313+
public operator fun DateTimePeriod.plus(other: DateTimePeriod): DateTimePeriod = buildDateTimePeriod(
314314
safeAdd(totalMonths, other.totalMonths),
315315
safeAdd(days, other.days),
316316
safeAdd(totalNanoseconds, other.totalNanoseconds),
317317
)
318318

319-
operator fun DatePeriod.plus(other: DatePeriod): DatePeriod = DatePeriod(
319+
public operator fun DatePeriod.plus(other: DatePeriod): DatePeriod = DatePeriod(
320320
safeAdd(totalMonths, other.totalMonths),
321321
safeAdd(days, other.days),
322322
)

core/common/src/DateTimeUnit.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import kotlinx.serialization.Serializable
1010
import kotlin.time.*
1111

1212
@Serializable(with = DateTimeUnitSerializer::class)
13-
sealed class DateTimeUnit {
13+
public sealed class DateTimeUnit {
1414

15-
abstract operator fun times(scalar: Int): DateTimeUnit
15+
public abstract operator fun times(scalar: Int): DateTimeUnit
1616

1717
@Serializable(with = TimeBasedDateTimeUnitSerializer::class)
18-
class TimeBased(val nanoseconds: Long) : DateTimeUnit() {
18+
public class TimeBased(public val nanoseconds: Long) : DateTimeUnit() {
1919
private val unitName: String
2020
private val unitScale: Long
2121

@@ -53,7 +53,7 @@ sealed class DateTimeUnit {
5353
override fun times(scalar: Int): TimeBased = TimeBased(safeMultiply(nanoseconds, scalar.toLong()))
5454

5555
@ExperimentalTime
56-
val duration: Duration
56+
public val duration: Duration
5757
get() = nanoseconds.nanoseconds
5858

5959
override fun equals(other: Any?): Boolean =
@@ -65,10 +65,10 @@ sealed class DateTimeUnit {
6565
}
6666

6767
@Serializable(with = DateBasedDateTimeUnitSerializer::class)
68-
sealed class DateBased : DateTimeUnit() {
68+
public sealed class DateBased : DateTimeUnit() {
6969
// TODO: investigate how to move subclasses up to DateTimeUnit scope
7070
@Serializable(with = DayBasedDateTimeUnitSerializer::class)
71-
class DayBased(val days: Int) : DateBased() {
71+
public class DayBased(public val days: Int) : DateBased() {
7272
init {
7373
require(days > 0) { "Unit duration must be positive, but was $days days." }
7474
}
@@ -86,7 +86,7 @@ sealed class DateTimeUnit {
8686
formatToString(days, "DAY")
8787
}
8888
@Serializable(with = MonthBasedDateTimeUnitSerializer::class)
89-
class MonthBased(val months: Int) : DateBased() {
89+
public class MonthBased(public val months: Int) : DateBased() {
9090
init {
9191
require(months > 0) { "Unit duration must be positive, but was $months months." }
9292
}
@@ -110,18 +110,18 @@ sealed class DateTimeUnit {
110110
protected fun formatToString(value: Int, unit: String): String = if (value == 1) unit else "$value-$unit"
111111
protected fun formatToString(value: Long, unit: String): String = if (value == 1L) unit else "$value-$unit"
112112

113-
companion object {
114-
val NANOSECOND = TimeBased(nanoseconds = 1)
115-
val MICROSECOND = NANOSECOND * 1000
116-
val MILLISECOND = MICROSECOND * 1000
117-
val SECOND = MILLISECOND * 1000
118-
val MINUTE = SECOND * 60
119-
val HOUR = MINUTE * 60
120-
val DAY = DateBased.DayBased(days = 1)
121-
val WEEK = DAY * 7
122-
val MONTH = DateBased.MonthBased(months = 1)
123-
val QUARTER = MONTH * 3
124-
val YEAR = MONTH * 12
125-
val CENTURY = YEAR * 100
113+
public companion object {
114+
public val NANOSECOND: TimeBased = TimeBased(nanoseconds = 1)
115+
public val MICROSECOND: TimeBased = NANOSECOND * 1000
116+
public val MILLISECOND: TimeBased = MICROSECOND * 1000
117+
public val SECOND: TimeBased = MILLISECOND * 1000
118+
public val MINUTE: TimeBased = SECOND * 60
119+
public val HOUR: TimeBased = MINUTE * 60
120+
public val DAY: DateBased.DayBased = DateBased.DayBased(days = 1)
121+
public val WEEK: DateBased.DayBased = DAY * 7
122+
public val MONTH: DateBased.MonthBased = DateBased.MonthBased(months = 1)
123+
public val QUARTER: DateBased.MonthBased = MONTH * 3
124+
public val YEAR: DateBased.MonthBased = MONTH * 12
125+
public val CENTURY: DateBased.MonthBased = YEAR * 100
126126
}
127127
}

core/common/src/Exceptions.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class IllegalTimeZoneException: IllegalArgumentException {
2020
}
2121

2222
internal class DateTimeFormatException: IllegalArgumentException {
23-
public constructor(): super()
24-
public constructor(message: String): super(message)
25-
public constructor(cause: Throwable): super(cause)
26-
public constructor(message: String, cause: Throwable): super(message, cause)
23+
constructor(): super()
24+
constructor(message: String): super(message)
25+
constructor(cause: Throwable): super(cause)
26+
constructor(message: String, cause: Throwable): super(message, cause)
2727
}

core/common/src/Instant.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,32 +94,32 @@ public expect class Instant : Comparable<Instant> {
9494
public override fun toString(): String
9595

9696

97-
companion object {
97+
public companion object {
9898
@Deprecated("Use Clock.System.now() instead", ReplaceWith("Clock.System.now()", "kotlinx.datetime.Clock"), level = DeprecationLevel.ERROR)
99-
fun now(): Instant
99+
public fun now(): Instant
100100

101101
/**
102102
* Returns an [Instant] that is [epochMilliseconds] number of milliseconds from the epoch instant `1970-01-01T00:00:00Z`.
103103
*
104104
* The return value is clamped to the platform-specific boundaries for [Instant] if the result exceeds them.
105105
*/
106-
fun fromEpochMilliseconds(epochMilliseconds: Long): Instant
106+
public fun fromEpochMilliseconds(epochMilliseconds: Long): Instant
107107

108108
/**
109109
* Returns an [Instant] that is the [epochSeconds] number of seconds from the epoch instant `1970-01-01T00:00:00Z`
110110
* and the [nanosecondAdjustment] number of nanoseconds from the whole second.
111111
*
112112
* The return value is clamped to the platform-specific boundaries for [Instant] if the result exceeds them.
113113
*/
114-
fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Long = 0): Instant
114+
public fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Long = 0): Instant
115115

116116
/**
117117
* Returns an [Instant] that is the [epochSeconds] number of seconds from the epoch instant `1970-01-01T00:00:00Z`
118118
* and the [nanosecondAdjustment] number of nanoseconds from the whole second.
119119
*
120120
* The return value is clamped to the platform-specific boundaries for [Instant] if the result exceeds them.
121121
*/
122-
fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Int): Instant
122+
public fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Int): Instant
123123

124124
/**
125125
* Parses a string that represents an instant in ISO-8601 format including date and time components and
@@ -132,7 +132,7 @@ public expect class Instant : Comparable<Instant> {
132132
*
133133
* @throws IllegalArgumentException if the text cannot be parsed or the boundaries of [Instant] are exceeded.
134134
*/
135-
fun parse(isoString: String): Instant
135+
public fun parse(isoString: String): Instant
136136

137137

138138
/**
@@ -141,27 +141,27 @@ public expect class Instant : Comparable<Instant> {
141141
* All instants in the range `DISTANT_PAST..DISTANT_FUTURE` can be converted to [LocalDateTime][Instant.toLocalDateTime]
142142
* without exceptions on all supported platforms.
143143
*/
144-
val DISTANT_PAST: Instant // -100001-12-31T23:59:59.999999999Z
144+
public val DISTANT_PAST: Instant // -100001-12-31T23:59:59.999999999Z
145145

146146
/**
147147
* An instant value that is far in the future.
148148
*
149149
* All instants in the range `DISTANT_PAST..DISTANT_FUTURE` can be converted to [LocalDateTime][Instant.toLocalDateTime]
150150
* without exceptions on all supported platforms.
151151
*/
152-
val DISTANT_FUTURE: Instant // +100000-01-01T00:00:00Z
152+
public val DISTANT_FUTURE: Instant // +100000-01-01T00:00:00Z
153153

154154
internal val MIN: Instant
155155
internal val MAX: Instant
156156
}
157157
}
158158

159159
/** Returns true if the instant is not later than [Instant.DISTANT_PAST]. */
160-
public val Instant.isDistantPast
160+
public val Instant.isDistantPast: Boolean
161161
get() = this <= Instant.DISTANT_PAST
162162

163163
/** Returns true if the instant is not earlier than [Instant.DISTANT_FUTURE]. */
164-
public val Instant.isDistantFuture
164+
public val Instant.isDistantFuture: Boolean
165165
get() = this >= Instant.DISTANT_FUTURE
166166

167167
/**
@@ -408,7 +408,7 @@ public expect fun Instant.plus(value: Long, unit: DateTimeUnit, timeZone: TimeZo
408408
*
409409
* @throws DateTimeArithmeticException if this value or the result is too large to fit in [LocalDateTime].
410410
*/
411-
public fun Instant.minus(value: Long, unit: DateTimeUnit, timeZone: TimeZone) =
411+
public fun Instant.minus(value: Long, unit: DateTimeUnit, timeZone: TimeZone): Instant =
412412
if (value != Long.MIN_VALUE) {
413413
plus(-value, unit, timeZone)
414414
} else {

core/common/src/LocalDate.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable
1010

1111
@Serializable(with = LocalDateIso8601Serializer::class)
1212
public expect class LocalDate : Comparable<LocalDate> {
13-
companion object {
13+
public companion object {
1414
/**
1515
* Parses a string that represents a date in ISO-8601 format
1616
* and returns the parsed [LocalDate] value.
@@ -112,7 +112,7 @@ public fun LocalDate.atTime(hour: Int, minute: Int, second: Int = 0, nanosecond:
112112
* @throws DateTimeArithmeticException if this value or the results of intermediate computations are too large to fit in
113113
* [LocalDate].
114114
*/
115-
expect operator fun LocalDate.plus(period: DatePeriod): LocalDate
115+
public expect operator fun LocalDate.plus(period: DatePeriod): LocalDate
116116

117117
/**
118118
* Returns a date that is the result of subtracting components of [DatePeriod] from this date. The components are
@@ -145,7 +145,7 @@ public operator fun LocalDate.minus(period: DatePeriod): LocalDate =
145145
*
146146
* @see LocalDate.minus
147147
*/
148-
expect fun LocalDate.periodUntil(other: LocalDate): DatePeriod
148+
public expect fun LocalDate.periodUntil(other: LocalDate): DatePeriod
149149

150150
/**
151151
* Returns a [DatePeriod] representing the difference between [other] and `this` dates.
@@ -161,7 +161,7 @@ expect fun LocalDate.periodUntil(other: LocalDate): DatePeriod
161161
*
162162
* @see LocalDate.periodUntil
163163
*/
164-
operator fun LocalDate.minus(other: LocalDate): DatePeriod = other.periodUntil(this)
164+
public operator fun LocalDate.minus(other: LocalDate): DatePeriod = other.periodUntil(this)
165165

166166
/**
167167
* Returns the whole number of the specified date [units][unit] between `this` and [other] dates.

core/common/src/LocalDateTime.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable
1010

1111
@Serializable(with = LocalDateTimeIso8601Serializer::class)
1212
public expect class LocalDateTime : Comparable<LocalDateTime> {
13-
companion object {
13+
public companion object {
1414

1515
/**
1616
* Parses a string that represents a date/time value in ISO-8601 format including date and time components

core/common/src/TimeZone.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ public expect open class TimeZone {
2121
*/
2222
public val id: String
2323

24-
companion object {
24+
public companion object {
2525
/**
2626
* Queries the current system time zone.
2727
*
2828
* If the current system time zone changes, this function can reflect this change on the next invocation.
2929
*/
30-
fun currentSystemDefault(): TimeZone
30+
public fun currentSystemDefault(): TimeZone
3131

3232
/**
3333
* Returns the time zone with the fixed UTC+0 offset.
3434
*/
35-
val UTC: TimeZone
35+
public val UTC: TimeZone
3636

3737
/**
3838
* Returns the time zone identified by the provided [zoneId].
@@ -48,12 +48,12 @@ public expect open class TimeZone {
4848
* @throws IllegalTimeZoneException if [zoneId] has an invalid format or a time-zone with the name [zoneId]
4949
* is not found.
5050
*/
51-
fun of(zoneId: String): TimeZone
51+
public fun of(zoneId: String): TimeZone
5252

5353
/**
5454
* Queries the set of identifiers of time zones available in the system.
5555
*/
56-
val availableZoneIds: Set<String>
56+
public val availableZoneIds: Set<String>
5757
}
5858

5959
/**
@@ -87,7 +87,7 @@ public expect open class TimeZone {
8787

8888
@Serializable(with = ZoneOffsetSerializer::class)
8989
public expect class ZoneOffset : TimeZone {
90-
val totalSeconds: Int
90+
public val totalSeconds: Int
9191
}
9292

9393
/**

0 commit comments

Comments
 (0)