From 49d07a046d136a122c5a973f276f393704de0be2 Mon Sep 17 00:00:00 2001 From: Eirik Vale Aase Date: Fri, 17 Nov 2023 09:31:17 +0100 Subject: [PATCH] Fix log files not being uploaded because of a `LogDate` being `null` (#3) Co-authored-by: Noor Dawod --- build.gradle.kts | 2 +- .../kotlin/com/airthings/lib/logging/LogDate.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 323d9bc..8895025 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ */ rootProject.group = "com.airthings.lib" -rootProject.version = "0.1.4" +rootProject.version = "0.1.5" buildscript { repositories { diff --git a/src/commonMain/kotlin/com/airthings/lib/logging/LogDate.kt b/src/commonMain/kotlin/com/airthings/lib/logging/LogDate.kt index ae5072f..3963aed 100644 --- a/src/commonMain/kotlin/com/airthings/lib/logging/LogDate.kt +++ b/src/commonMain/kotlin/com/airthings/lib/logging/LogDate.kt @@ -29,6 +29,7 @@ import kotlinx.datetime.LocalDateTime * @param year The year part of the date. * @param month The month part of the date, within the range of 1..12. * @param day The day part of the date, within the range of 1..31. + * @param separator The character used to separate the date parts, defaults to [SEPARATOR]. */ data class LogDate( val year: Int, @@ -55,6 +56,13 @@ data class LogDate( override fun toString(): String = toString(separator) override fun hashCode(): Int = toString(null).toIntOrNull() ?: toString().hashCode() + + companion object { + /** + * The character used to separate date parts, f.ex: `2023-08-23`. + */ + const val SEPARATOR = '-' + } } internal fun LogDate.toString(separator: Char?): String = StringBuilder(10) @@ -101,7 +109,7 @@ internal fun LogDate.after(another: LogDate): Boolean = year > another.year || */ internal fun String.ifAfter(date: LogDate?): Boolean { val fileNameWithoutExtension = substringBeforeLast('.') - val logDate = fileNameWithoutExtension.asLogDate(date?.separator) + val logDate = fileNameWithoutExtension.asLogDate(date?.separator ?: LogDate.SEPARATOR) return logDate != null && (date == null || logDate.after(date)) }