Skip to content

Commit d52f0cb

Browse files
committed
Address the review
1 parent a9fe69f commit d52f0cb

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

core/commonJs/src/internal/Platform.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,23 @@ private val tzdb: Result<TimeZoneDatabase?> = runCatching {
2525
}
2626
/** converts a base60 number of minutes to a whole number of seconds */
2727
fun base60MinutesInSeconds(string: String): Long {
28-
var i = 0
29-
var parts = string.split('.')
28+
val parts = string.split('.')
3029

3130
// handle negative numbers
32-
val sign = if (string.startsWith('-')) {
33-
i = 1
34-
-1
31+
val sign: Int
32+
val minuteNumberStart: Int
33+
if (string.startsWith('-')) {
34+
minuteNumberStart = 1
35+
sign = -1
3536
} else {
36-
1
37+
minuteNumberStart = 0
38+
sign = 1
3739
}
3840

39-
var wholeMinutes: Long = 0
40-
val whole = parts[0]
4141
// handle digits before the decimal (whole minutes)
42-
for (ix in i..whole.lastIndex) {
43-
wholeMinutes = 60 * wholeMinutes + charCodeToInt(whole[ix])
42+
val whole = parts[0]
43+
val wholeMinutes: Long = (minuteNumberStart..whole.lastIndex).map { charCodeToInt(whole[it]) }.fold(0L) {
44+
acc, digit -> 60 * acc + digit
4445
}
4546

4647
// handle digits after the decimal (seconds and less)

core/commonKotlin/src/internal/MonthDayTime.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ internal interface DateOfYear {
2828

2929
/**
3030
* The day of year, in the 0..365 range. During leap years, 29th February is counted as the 60th day of the year.
31-
* The number 366 is not supported, as outside the leap years, there are only 365 days in a year.
3231
*/
3332
internal class JulianDayOfYear(val zeroBasedDayOfYear: Int) : DateOfYear {
3433
init {
3534
require(zeroBasedDayOfYear in 0..365) {
36-
"Expected a value in 1..365 for the Julian day-of-year, but got $zeroBasedDayOfYear"
35+
"Expected a value in 0..365 for the Julian day-of-year, but got $zeroBasedDayOfYear"
3736
}
3837
}
3938
override fun toLocalDate(year: Int): LocalDate =

0 commit comments

Comments
 (0)