Skip to content

Commit 453861d

Browse files
committed
moneymong-306 feature: OCR 결과 날짜, 시간 형식 검증 추가
1 parent d684326 commit 453861d

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

feature/ocr-detail/src/main/java/com/moneymong/moneymong/ocr_detail/OCRDetailViewModel.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,23 @@ class OCRDetailViewModel @Inject constructor(
4444
val receipt = document?.images?.first()?.receipt?.result
4545
val currentDate = SimpleDateFormat("yyyyMMdd", Locale.KOREA).format(Date(System.currentTimeMillis()))
4646
val currentTime = SimpleDateFormat("HHmmss", Locale.KOREA).format(Date(System.currentTimeMillis()))
47-
val paymentDateString = receipt?.paymentInfo?.date?.let {
48-
"${it.formatted?.year}${it.formatted?.month}${it.formatted?.day}"
47+
val paymentDateString = receipt?.paymentInfo?.date?.formatted?.let {
48+
("${it.year}${it.month}${it.day}").run {
49+
if (validateValue(length = 8, isDigit = true) && isValidPaymentDate()) {
50+
this
51+
} else {
52+
currentDate
53+
}
54+
}
4955
} ?: currentDate
50-
val paymentTimeString = receipt?.paymentInfo?.time?.let {
51-
"${it.formatted?.hour}${it.formatted?.minute}${it.formatted?.second}"
56+
val paymentTimeString = receipt?.paymentInfo?.time?.formatted?.let {
57+
("${it.hour}${it.minute}${it.second}").run {
58+
if (validateValue(length = 6, isDigit = true) && isValidPaymentTime()) {
59+
this
60+
} else {
61+
currentTime
62+
}
63+
}
5264
} ?: currentTime
5365
reduce {
5466
state.copy(

feature/ocr-result/src/main/java/com/moneymong/moneymong/ocr_result/OCRResultState.kt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package com.moneymong.moneymong.ocr_result
22

33
import com.moneymong.moneymong.common.base.State
44
import com.moneymong.moneymong.common.ext.toZonedDateTime
5+
import com.moneymong.moneymong.common.ui.isValidPaymentDate
6+
import com.moneymong.moneymong.common.ui.isValidPaymentTime
57
import com.moneymong.moneymong.common.ui.toWonFormat
8+
import com.moneymong.moneymong.common.ui.validateValue
69
import com.moneymong.moneymong.domain.entity.ocr.DocumentEntity
710
import com.moneymong.moneymong.domain.entity.ocr.DocumentResultEntity
811
import java.io.File
@@ -46,16 +49,28 @@ data class OCRResultState(
4649
val formattedDate: String
4750
get() {
4851
val currentDate = SimpleDateFormat("yyyy년 MM월 dd일", Locale.KOREA).format(Date(System.currentTimeMillis()))
49-
return receipt?.paymentInfo?.date?.let {
50-
"${it.formatted?.year}${it.formatted?.month}${it.formatted?.day}"
52+
return receipt?.paymentInfo?.date?.formatted?.let {
53+
("${it.year}${it.month}${it.day}").run {
54+
if (validateValue(length = 8, isDigit = true) && isValidPaymentDate()) {
55+
"${it.year}${it.month}${it.day}"
56+
} else {
57+
currentDate
58+
}
59+
}
5160
} ?: currentDate
5261
}
5362

5463
val formattedTime: String
5564
get() {
5665
val currentTime = SimpleDateFormat("HH:mm:ss", Locale.KOREA).format(Date(System.currentTimeMillis()))
57-
return receipt?.paymentInfo?.time?.let {
58-
"${it.formatted?.hour}:${it.formatted?.minute}:${it.formatted?.second}"
66+
return receipt?.paymentInfo?.time?.formatted?.let {
67+
("${it.hour}${it.minute}${it.second}").run {
68+
if (validateValue(length = 6, isDigit = true) && isValidPaymentTime()) {
69+
"${it.hour}:${it.minute}:${it.second}"
70+
} else {
71+
currentTime
72+
}
73+
}
5974
} ?: currentTime
6075
}
6176

0 commit comments

Comments
 (0)