From 4f73a74c4852b7c3ee68a3fb42406244bde5dad4 Mon Sep 17 00:00:00 2001 From: Kumar Rishi Date: Sun, 2 Jun 2024 05:37:10 +0530 Subject: [PATCH] [FIX] TimeZone Issue Fix (#3224) --- .../ivy/data/repository/mapper/TransactionMapper.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/shared/data/core/src/main/java/com/ivy/data/repository/mapper/TransactionMapper.kt b/shared/data/core/src/main/java/com/ivy/data/repository/mapper/TransactionMapper.kt index 70a1c574ee..0004813c82 100644 --- a/shared/data/core/src/main/java/com/ivy/data/repository/mapper/TransactionMapper.kt +++ b/shared/data/core/src/main/java/com/ivy/data/repository/mapper/TransactionMapper.kt @@ -11,18 +11,19 @@ import com.ivy.data.model.AccountId import com.ivy.data.model.CategoryId import com.ivy.data.model.Expense import com.ivy.data.model.Income +import com.ivy.data.model.PositiveValue +import com.ivy.data.model.TagId import com.ivy.data.model.Transaction import com.ivy.data.model.TransactionId import com.ivy.data.model.TransactionMetadata import com.ivy.data.model.Transfer -import com.ivy.data.model.PositiveValue import com.ivy.data.model.getFromAccount import com.ivy.data.model.getToAccount import com.ivy.data.model.primitive.NotBlankTrimmedString import com.ivy.data.model.primitive.PositiveDouble -import com.ivy.data.model.TagId import com.ivy.data.repository.AccountRepository import java.time.Instant +import java.time.ZoneOffset import javax.inject.Inject class TransactionMapper @Inject constructor( @@ -35,10 +36,11 @@ class TransactionMapper @Inject constructor( ): Either = either { val metadata = TransactionMetadata( recurringRuleId = recurringRuleId, - paidForDateTime = paidForDateTime?.atZone(timeProvider.getZoneId())?.toInstant(), + paidForDateTime = paidForDateTime?.toInstant(ZoneOffset.UTC), loanId = loanId, loanRecordId = loanRecordId ) + val settled = dateTime != null val time = mapTime().bind() @@ -132,13 +134,13 @@ class TransactionMapper @Inject constructor( } private fun TransactionEntity.mapTime(): Either = either { - val time = (dateTime ?: dueDate)?.atZone(timeProvider.getZoneId())?.toInstant() + val time = (dateTime ?: dueDate)?.toInstant(ZoneOffset.UTC) ensureNotNull(time) { "Missing transaction time for entity: $this" } time } fun Transaction.toEntity(): TransactionEntity { - val dateTime = time.atZone(timeProvider.getZoneId()).toLocalDateTime() + val dateTime = time.atZone(ZoneOffset.UTC).toLocalDateTime() return TransactionEntity( accountId = getFromAccount().value, type = when (this) {