Skip to content

Commit

Permalink
Fix log files not being uploaded because of a LogDate being null (#3
Browse files Browse the repository at this point in the history
)

Co-authored-by: Noor Dawod <[email protected]>
  • Loading branch information
eirikvaa and airxnoor authored Nov 17, 2023
1 parent 47f6a90 commit 49d07a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

rootProject.group = "com.airthings.lib"
rootProject.version = "0.1.4"
rootProject.version = "0.1.5"

buildscript {
repositories {
Expand Down
10 changes: 9 additions & 1 deletion src/commonMain/kotlin/com/airthings/lib/logging/LogDate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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))
}

0 comments on commit 49d07a0

Please sign in to comment.