12 Сделать добавление транзакций на фронте, добавить уже сгенерированые экраны в проект
This commit is contained in:
@@ -13,9 +13,9 @@ var knownDateFormats = []string{
|
||||
"02.01.06", // 21.01.2026
|
||||
"02-01-2006", // 21-01-2026
|
||||
"02/01/2006", // 21/01/2026
|
||||
//"2006/01/02", // 2026/01/21
|
||||
//"2006-01-02", // 2026-01-21
|
||||
//"2006.01.02", // 2026.01.21
|
||||
"2006/01/02", // 2026/01/21
|
||||
"2006-01-02", // 2026-01-21
|
||||
"2006.01.02", // 2026.01.21
|
||||
}
|
||||
|
||||
func NormalizeDateToISO(input string) (string, error) {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package utils
|
||||
|
||||
import "regexp"
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ReceiptMeta struct {
|
||||
Date string
|
||||
@@ -10,17 +14,16 @@ type ReceiptMeta struct {
|
||||
func ExtractReceiptMeta(text string) ReceiptMeta {
|
||||
result := ReceiptMeta{}
|
||||
|
||||
// --- ДАТА ---
|
||||
datePatterns := []string{
|
||||
`(\d{2}[./-]\d{2}[./-]\d{4})`, // 25.01.2026
|
||||
`(\d{2}[./-]\d{2}[./-]\d{2})`, // 25.01.26
|
||||
`(\d{4}[./-]\d{2}[./-]\d{2})`, // 2026-01-25
|
||||
`\b\d{2}[./:-]\d{2}[./:-]\d{4}\b`, // 25.01.2026, 25:01.2026
|
||||
`\b\d{4}[./:-]\d{2}[./:-]\d{2}\b`, // 2026-01-25
|
||||
`\b\d{2}[./-]\d{2}[./-]\d{2}\b`, // 25.01.26
|
||||
}
|
||||
|
||||
for _, pattern := range datePatterns {
|
||||
re := regexp.MustCompile(pattern)
|
||||
if match := re.FindString(text); match != "" {
|
||||
result.Date = match
|
||||
result.Date = normalizeOCRDate(match)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -31,3 +34,15 @@ func ExtractReceiptMeta(text string) ReceiptMeta {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func normalizeOCRDate(value string) string {
|
||||
sanitized := strings.NewReplacer(":", ".", "/", ".", "-", ".").Replace(strings.TrimSpace(value))
|
||||
|
||||
for _, layout := range knownDateFormats {
|
||||
if t, err := time.Parse(layout, sanitized); err == nil {
|
||||
return t.Format("02.01.2006")
|
||||
}
|
||||
}
|
||||
|
||||
return strings.TrimSpace(value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user