From 68f455a77b9a99846acbb74e6dbbd7e6ec46d3f8 Mon Sep 17 00:00:00 2001 From: akashs056 Date: Fri, 30 Aug 2024 17:46:18 +0530 Subject: [PATCH 1/6] fix csv export --- .../java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt b/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt index 494213f015..d4d2ab3799 100644 --- a/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt +++ b/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt @@ -4,6 +4,7 @@ import android.net.Uri import arrow.core.Either import com.ivy.base.model.TransactionType import com.ivy.base.threading.DispatchersProvider +import com.ivy.base.time.TimeProvider import com.ivy.data.file.FileSystem import com.ivy.data.model.Account import com.ivy.data.model.AccountId @@ -23,7 +24,6 @@ import org.apache.commons.text.StringEscapeUtils import java.text.DecimalFormat import java.text.DecimalFormatSymbols import java.time.Instant -import java.time.ZoneId import java.time.format.DateTimeFormatter import java.util.Locale import javax.inject.Inject @@ -34,7 +34,8 @@ class ExportCsvUseCase @Inject constructor( private val categoryRepository: CategoryRepository, private val transactionRepository: TransactionRepository, private val dispatchers: DispatchersProvider, - private val fileSystem: FileSystem + private val fileSystem: FileSystem, + private val timeProvider: TimeProvider ) { suspend fun exportToFile( @@ -188,7 +189,8 @@ class ExportCsvUseCase @Inject constructor( ) private fun Instant.csvFormat(): String { - return this.atZone(ZoneId.of("UTC")).toLocalDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + return this.atZone(timeProvider.getZoneId()) + .format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) } private fun Double.csvFormat(): String = DecimalFormat(NUMBER_FORMAT).apply { From 5d72f9a682617217227397ef52b84203a45171e5 Mon Sep 17 00:00:00 2001 From: akashs056 Date: Fri, 30 Aug 2024 18:47:01 +0530 Subject: [PATCH 2/6] use timeconverter API --- .../java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt b/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt index d4d2ab3799..b9d17ac6bf 100644 --- a/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt +++ b/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt @@ -4,6 +4,7 @@ import android.net.Uri import arrow.core.Either import com.ivy.base.model.TransactionType import com.ivy.base.threading.DispatchersProvider +import com.ivy.base.time.TimeConverter import com.ivy.base.time.TimeProvider import com.ivy.data.file.FileSystem import com.ivy.data.model.Account @@ -35,7 +36,8 @@ class ExportCsvUseCase @Inject constructor( private val transactionRepository: TransactionRepository, private val dispatchers: DispatchersProvider, private val fileSystem: FileSystem, - private val timeProvider: TimeProvider + private val timeProvider: TimeProvider, + private val timeConverter: TimeConverter ) { suspend fun exportToFile( @@ -189,8 +191,9 @@ class ExportCsvUseCase @Inject constructor( ) private fun Instant.csvFormat(): String { - return this.atZone(timeProvider.getZoneId()) - .format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + return with(timeConverter) { + this@csvFormat.toLocalDateTime() + }.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) } private fun Double.csvFormat(): String = DecimalFormat(NUMBER_FORMAT).apply { From 1d87addd4bbc92e53fd74950c67543e5710a4a94 Mon Sep 17 00:00:00 2001 From: akashs056 Date: Fri, 30 Aug 2024 18:55:48 +0530 Subject: [PATCH 3/6] fix detekt --- .../main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt b/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt index b9d17ac6bf..23a56f6a00 100644 --- a/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt +++ b/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt @@ -5,7 +5,6 @@ import arrow.core.Either import com.ivy.base.model.TransactionType import com.ivy.base.threading.DispatchersProvider import com.ivy.base.time.TimeConverter -import com.ivy.base.time.TimeProvider import com.ivy.data.file.FileSystem import com.ivy.data.model.Account import com.ivy.data.model.AccountId @@ -36,7 +35,6 @@ class ExportCsvUseCase @Inject constructor( private val transactionRepository: TransactionRepository, private val dispatchers: DispatchersProvider, private val fileSystem: FileSystem, - private val timeProvider: TimeProvider, private val timeConverter: TimeConverter ) { From 6f08194ff7ac9219c7ec622216a1be668319fda7 Mon Sep 17 00:00:00 2001 From: akashs056 Date: Sat, 31 Aug 2024 11:21:56 +0530 Subject: [PATCH 4/6] implement TestTimeConverter and fix ExportCsvUseCasePropertyTest --- .../ivy/base/time/impl/TestTimeConverter.kt | 27 +++++++++++++++++++ .../domain/usecase/csv/ExportCsvUseCase.kt | 6 ++--- .../csv/ExportCsvUseCasePropertyTest.kt | 3 +++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt diff --git a/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt b/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt new file mode 100644 index 0000000000..e13dcfd943 --- /dev/null +++ b/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt @@ -0,0 +1,27 @@ +package com.ivy.base.time.impl + +import com.ivy.base.time.TimeConverter +import java.time.Instant +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.ZoneId + +class TestTimeConverter : TimeConverter { + private val utcZoneId = ZoneId.of("UTC") + + override fun Instant.toLocalDateTime(): LocalDateTime { + return this.atZone(utcZoneId).toLocalDateTime() + } + + override fun Instant.toLocalDate(): LocalDate { + return this.atZone(utcZoneId).toLocalDate() + } + + override fun LocalDateTime.toUTC(): Instant { + return this.atZone(utcZoneId).toInstant() + } + + fun LocalDateTime.toInstant(): Instant { + return this.atZone(utcZoneId).toInstant() + } +} \ No newline at end of file diff --git a/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt b/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt index 23a56f6a00..98191461e9 100644 --- a/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt +++ b/shared/domain/src/main/java/com/ivy/domain/usecase/csv/ExportCsvUseCase.kt @@ -75,7 +75,7 @@ class ExportCsvUseCase @Inject constructor( categoriesMap: Map, ): String = csvRow { // Date - csvAppend(date?.csvFormat()) + csvAppend(date?.csvFormat(timeConverter)) // Title csvAppend(title?.value) // Category @@ -101,7 +101,7 @@ class ExportCsvUseCase @Inject constructor( // Description csvAppend(description?.value) // Due Date - csvAppend(dueData?.csvFormat()) + csvAppend(dueData?.csvFormat(timeConverter)) // ID csvAppend(id.value.toString()) } @@ -188,7 +188,7 @@ class ExportCsvUseCase @Inject constructor( id = id ) - private fun Instant.csvFormat(): String { + private fun Instant.csvFormat(timeConverter: TimeConverter): String { return with(timeConverter) { this@csvFormat.toLocalDateTime() }.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) diff --git a/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt b/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt index 02b4860b76..5f7071ddff 100644 --- a/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt +++ b/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt @@ -2,6 +2,7 @@ package com.ivy.domain.usecase.csv import arrow.core.Some import com.ivy.base.TestDispatchersProvider +import com.ivy.base.time.impl.TestTimeConverter import com.ivy.data.file.FileSystem import com.ivy.data.model.Transaction import com.ivy.data.model.getFromAccount @@ -30,6 +31,7 @@ class ExportCsvUseCasePropertyTest { private val categoryRepository = mockk(relaxed = true) private val transactionRepository = mockk() private val fileSystem = mockk() + private val timeConverter = TestTimeConverter() private lateinit var useCase: ExportCsvUseCase @@ -41,6 +43,7 @@ class ExportCsvUseCasePropertyTest { transactionRepository = transactionRepository, dispatchers = TestDispatchersProvider, fileSystem = fileSystem, + timeConverter = timeConverter, ) } From 9c396e6f2408db19240e57e4cf96198e1aa415e9 Mon Sep 17 00:00:00 2001 From: akashs056 Date: Sat, 31 Aug 2024 16:30:25 +0530 Subject: [PATCH 5/6] fix TestTimeConverter --- .../src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt | 4 ---- .../ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt b/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt index e13dcfd943..cb6cf613dd 100644 --- a/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt +++ b/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt @@ -20,8 +20,4 @@ class TestTimeConverter : TimeConverter { override fun LocalDateTime.toUTC(): Instant { return this.atZone(utcZoneId).toInstant() } - - fun LocalDateTime.toInstant(): Instant { - return this.atZone(utcZoneId).toInstant() - } } \ No newline at end of file diff --git a/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt b/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt index 5f7071ddff..d546e3f176 100644 --- a/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt +++ b/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt @@ -21,6 +21,8 @@ import io.kotest.property.arbitrary.next import io.kotest.property.checkAll import io.mockk.coEvery import io.mockk.mockk +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test @@ -43,7 +45,7 @@ class ExportCsvUseCasePropertyTest { transactionRepository = transactionRepository, dispatchers = TestDispatchersProvider, fileSystem = fileSystem, - timeConverter = timeConverter, + timeConverter = timeConverter ) } From 8a571cd5edac826664c38c8b3233837f1ea16974 Mon Sep 17 00:00:00 2001 From: akashs056 Date: Sun, 1 Sep 2024 18:09:03 +0530 Subject: [PATCH 6/6] WIP : fix gradle error --- .../main/java/com/ivy/base/time/impl/TestTimeConverter.kt | 5 +++++ .../ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt b/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt index cb6cf613dd..018309752f 100644 --- a/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt +++ b/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt @@ -4,6 +4,7 @@ import com.ivy.base.time.TimeConverter import java.time.Instant import java.time.LocalDate import java.time.LocalDateTime +import java.time.LocalTime import java.time.ZoneId class TestTimeConverter : TimeConverter { @@ -17,6 +18,10 @@ class TestTimeConverter : TimeConverter { return this.atZone(utcZoneId).toLocalDate() } + override fun Instant.toLocalTime(): LocalTime { + return this.atZone(utcZoneId).toLocalTime() + } + override fun LocalDateTime.toUTC(): Instant { return this.atZone(utcZoneId).toInstant() } diff --git a/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt b/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt index d546e3f176..10e3e75442 100644 --- a/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt +++ b/shared/domain/src/test/java/com/ivy/domain/usecase/csv/ExportCsvUseCasePropertyTest.kt @@ -21,8 +21,6 @@ import io.kotest.property.arbitrary.next import io.kotest.property.checkAll import io.mockk.coEvery import io.mockk.mockk -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test