Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
[FIX] TimeZone Issue Fix (#3224)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishi2062 authored Jun 2, 2024
1 parent 2ca6117 commit 4f73a74
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -35,10 +36,11 @@ class TransactionMapper @Inject constructor(
): Either<String, Transaction> = 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()

Expand Down Expand Up @@ -132,13 +134,13 @@ class TransactionMapper @Inject constructor(
}

private fun TransactionEntity.mapTime(): Either<String, Instant> = 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) {
Expand Down

0 comments on commit 4f73a74

Please sign in to comment.