From 131101d2eebdc39e8c0d44659895234b90facdb4 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sat, 29 Oct 2022 13:50:00 +0200 Subject: [PATCH] Date api issues. --- .../readerforselfossv2/utils/DateUtils.kt | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt b/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt index 26e21fd..8ff8dda 100644 --- a/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt +++ b/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt @@ -16,10 +16,18 @@ actual class DateUtils actual constructor(actual val appSettingsService: AppSett val FORMATTERV1 = "yyyy-MM-dd HH:mm:ss" return if (appSettingsService.getApiVersion() >= 4) { - OffsetDateTime.parse(dateString).toInstant().toEpochMilli() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + OffsetDateTime.parse(dateString).toInstant().toEpochMilli() + } else { + TODO("VERSION.SDK_INT < O") + } } else { - LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern(FORMATTERV1)).toInstant( - ZoneOffset.UTC).toEpochMilli() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern(FORMATTERV1)).toInstant( + ZoneOffset.UTC).toEpochMilli() + } else { + TODO("VERSION.SDK_INT < O") + } } } @@ -27,11 +35,15 @@ actual class DateUtils actual constructor(actual val appSettingsService: AppSett val date = parseDate(dateString) - return " " + DateUtils.getRelativeTimeSpanString( - date, - Instant.now().toEpochMilli(), - DateUtils.MINUTE_IN_MILLIS, - DateUtils.FORMAT_ABBREV_RELATIVE - ) + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + " " + DateUtils.getRelativeTimeSpanString( + date, + Instant.now().toEpochMilli(), + DateUtils.MINUTE_IN_MILLIS, + DateUtils.FORMAT_ABBREV_RELATIVE + ) + } else { + TODO("VERSION.SDK_INT < O") + } } } \ No newline at end of file