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..018309752f --- /dev/null +++ b/shared/base/src/main/java/com/ivy/base/time/impl/TestTimeConverter.kt @@ -0,0 +1,28 @@ +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.LocalTime +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 Instant.toLocalTime(): LocalTime { + return this.atZone(utcZoneId).toLocalTime() + } + + override fun LocalDateTime.toUTC(): 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 494213f015..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 @@ -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.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 timeConverter: TimeConverter ) { suspend fun exportToFile( @@ -74,7 +75,7 @@ class ExportCsvUseCase @Inject constructor( categoriesMap: Map, ): String = csvRow { // Date - csvAppend(date?.csvFormat()) + csvAppend(date?.csvFormat(timeConverter)) // Title csvAppend(title?.value) // Category @@ -100,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()) } @@ -187,8 +188,10 @@ class ExportCsvUseCase @Inject constructor( id = id ) - private fun Instant.csvFormat(): String { - return this.atZone(ZoneId.of("UTC")).toLocalDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + private fun Instant.csvFormat(timeConverter: TimeConverter): String { + return with(timeConverter) { + this@csvFormat.toLocalDateTime() + }.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) } private fun Double.csvFormat(): String = DecimalFormat(NUMBER_FORMAT).apply { 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..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 @@ -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 ) }