From 2fe4c8abf4d62f17cd89c2dca2a103826c6aaee5 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 28 Apr 2022 01:37:35 +0430 Subject: [PATCH] kotlin: Use single format instead multiple calls --- generate/template/astronomy.kt | 23 ++++--------------- .../github/cosinekitty/astronomy/astronomy.kt | 23 ++++--------------- 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/generate/template/astronomy.kt b/generate/template/astronomy.kt index fe07e33c..916c552c 100644 --- a/generate/template/astronomy.kt +++ b/generate/template/astronomy.kt @@ -451,22 +451,8 @@ class DateTime( val millis: Double = 1000.0 * (second - wholeSeconds) val wholeMillis: Int = millis.toInt() - return ( - "%04d".format(year) + - "-" + - "%02d".format(month) + - "-" + - "%02d".format(day) + - "T" + - "%02d".format(hour) + - ":" + - "%02d".format(minute) + - ":" + - "%02d".format(wholeSeconds) + - "." + - "%03d".format(wholeMillis) + - "Z" - ) + return "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ" + .format(year, month, day, hour, minute, wholeSeconds, wholeMillis) } } @@ -6477,8 +6463,7 @@ fun searchPeakMagnitude(body: Body, startTime: Time): IlluminationInfo { var iter = 0 var searchTime = startTime - while (++iter <= 2) - { + while (++iter <= 2) { // Find current heliocentric relative longitude between the // inferior planet and the Earth. val plon = eclipticLongitude(body, searchTime) @@ -7253,7 +7238,7 @@ internal fun planetExtreme(body: Body, kind: ApsisKind, startTime: Time, initDay for (i in 0 until npoints) { val time = searchTime.addDays(i * interval) val distance = direction * helioDistance(body, time) - if (i==0 || distance > bestDistance) { + if (i == 0 || distance > bestDistance) { bestI = i bestDistance = distance } diff --git a/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt b/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt index 11d16b92..b4b26962 100644 --- a/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt +++ b/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt @@ -451,22 +451,8 @@ class DateTime( val millis: Double = 1000.0 * (second - wholeSeconds) val wholeMillis: Int = millis.toInt() - return ( - "%04d".format(year) + - "-" + - "%02d".format(month) + - "-" + - "%02d".format(day) + - "T" + - "%02d".format(hour) + - ":" + - "%02d".format(minute) + - ":" + - "%02d".format(wholeSeconds) + - "." + - "%03d".format(wholeMillis) + - "Z" - ) + return "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ" + .format(year, month, day, hour, minute, wholeSeconds, wholeMillis) } } @@ -6477,8 +6463,7 @@ fun searchPeakMagnitude(body: Body, startTime: Time): IlluminationInfo { var iter = 0 var searchTime = startTime - while (++iter <= 2) - { + while (++iter <= 2) { // Find current heliocentric relative longitude between the // inferior planet and the Earth. val plon = eclipticLongitude(body, searchTime) @@ -7253,7 +7238,7 @@ internal fun planetExtreme(body: Body, kind: ApsisKind, startTime: Time, initDay for (i in 0 until npoints) { val time = searchTime.addDays(i * interval) val distance = direction * helioDistance(body, time) - if (i==0 || distance > bestDistance) { + if (i == 0 || distance > bestDistance) { bestI = i bestDistance = distance }