From e2f59774cc32cbae2384ccd433eb8940c35744f9 Mon Sep 17 00:00:00 2001 From: Ali Shanaakh Date: Sun, 4 Feb 2024 17:11:32 +0100 Subject: [PATCH] Fix --- pkg/portal/operation.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/portal/operation.go b/pkg/portal/operation.go index 6b3befb..eb7d880 100644 --- a/pkg/portal/operation.go +++ b/pkg/portal/operation.go @@ -37,17 +37,27 @@ type Operation struct { // FixDate returns fixed date in string format. func FixDate(lexeme string) string { - r := regexp.MustCompile(`^(\d{2})\.(\d{2})\.(\d{4})$`) + r2 := regexp.MustCompile(`^(\d{2})\.(\d{2})\.(\d{2})$`) + r4 := regexp.MustCompile(`^(\d{2})\.(\d{2})\.(\d{4})$`) - if !r.MatchString(lexeme) { - return lexeme + if r2.MatchString(lexeme) { + date := r2.ReplaceAllString(lexeme, "$1") + month := r2.ReplaceAllString(lexeme, "$2") + year := r2.ReplaceAllString(lexeme, "$3") + + return fmt.Sprintf("%s-%s-%s", year, month, "20"+date) + } + + if r4.MatchString(lexeme) { + date := r2.ReplaceAllString(lexeme, "$1") + month := r2.ReplaceAllString(lexeme, "$2") + year := r2.ReplaceAllString(lexeme, "$3") + + return fmt.Sprintf("%s-%s-%s", year, month, date) } - date := r.ReplaceAllString(lexeme, "$1") - month := r.ReplaceAllString(lexeme, "$2") - year := r.ReplaceAllString(lexeme, "$3") + return lexeme - return fmt.Sprintf("%s-%s-%s", year, month, date) } // FixBrandModel returns fixed brand.