@@ -14,17 +14,17 @@ import kotlinx.serialization.Serializable
14
14
15
15
@Serializable(with = DateTimePeriodIso8601Serializer ::class )
16
16
// TODO: could be error-prone without explicitly named params
17
- sealed class DateTimePeriod {
17
+ public sealed class DateTimePeriod {
18
18
internal abstract val totalMonths: Int
19
- abstract val days: Int
19
+ public abstract val days: Int
20
20
internal abstract val totalNanoseconds: Long
21
21
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()
28
28
29
29
private fun allNonpositive () =
30
30
totalMonths <= 0 && days <= 0 && totalNanoseconds <= 0 && (totalMonths or days != 0 || totalNanoseconds != 0L )
@@ -70,8 +70,8 @@ sealed class DateTimePeriod {
70
70
return result
71
71
}
72
72
73
- companion object {
74
- fun parse (text : String ): DateTimePeriod {
73
+ public companion object {
74
+ public fun parse (text : String ): DateTimePeriod {
75
75
fun parseException (message : String , position : Int ): Nothing =
76
76
throw DateTimeFormatException (" Parse error at char $position : $message " )
77
77
val START = 0
@@ -238,20 +238,20 @@ sealed class DateTimePeriod {
238
238
public fun String.toDateTimePeriod (): DateTimePeriod = DateTimePeriod .parse(this )
239
239
240
240
@Serializable(with = DatePeriodIso8601Serializer ::class )
241
- class DatePeriod internal constructor(
241
+ public class DatePeriod internal constructor(
242
242
internal override val totalMonths : Int ,
243
243
override val days : Int ,
244
244
) : 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)
246
246
// avoiding excessive computations
247
247
override val hours: Int get() = 0
248
248
override val minutes: Int get() = 0
249
249
override val seconds: Int get() = 0
250
250
override val nanoseconds: Int get() = 0
251
251
internal override val totalNanoseconds: Long get() = 0
252
252
253
- companion object {
254
- fun parse (text : String ): DatePeriod =
253
+ public companion object {
254
+ public fun parse (text : String ): DatePeriod =
255
255
when (val period = DateTimePeriod .parse(text)) {
256
256
is DatePeriod -> period
257
257
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
296
296
else
297
297
DatePeriod (totalMonths, days)
298
298
299
- fun DateTimePeriod (
299
+ public fun DateTimePeriod (
300
300
years : Int = 0,
301
301
months : Int = 0,
302
302
days : Int = 0,
@@ -308,15 +308,15 @@ fun DateTimePeriod(
308
308
totalNanoseconds(hours, minutes, seconds, nanoseconds))
309
309
310
310
@OptIn(ExperimentalTime ::class )
311
- fun Duration.toDateTimePeriod (): DateTimePeriod = buildDateTimePeriod(totalNanoseconds = toLongNanoseconds())
311
+ public fun Duration.toDateTimePeriod (): DateTimePeriod = buildDateTimePeriod(totalNanoseconds = toLongNanoseconds())
312
312
313
- operator fun DateTimePeriod.plus (other : DateTimePeriod ): DateTimePeriod = buildDateTimePeriod(
313
+ public operator fun DateTimePeriod.plus (other : DateTimePeriod ): DateTimePeriod = buildDateTimePeriod(
314
314
safeAdd(totalMonths, other.totalMonths),
315
315
safeAdd(days, other.days),
316
316
safeAdd(totalNanoseconds, other.totalNanoseconds),
317
317
)
318
318
319
- operator fun DatePeriod.plus (other : DatePeriod ): DatePeriod = DatePeriod (
319
+ public operator fun DatePeriod.plus (other : DatePeriod ): DatePeriod = DatePeriod (
320
320
safeAdd(totalMonths, other.totalMonths),
321
321
safeAdd(days, other.days),
322
322
)
0 commit comments