Files
alfred-be/alfred/utils/index_utils.go
2026-03-08 16:14:42 +05:30

29 lines
716 B
Go

package utils
import (
"alfred/pkg/log"
"go.uber.org/zap"
"regexp"
"time"
)
func CompareDateAndFindKey(indexName string, case1, case2, date string) string {
indexDateRegex := regexp.MustCompile(IndexDateRegex)
indexDate := NormalizeDate(indexDateRegex.FindStringSubmatch(indexName)[1])
compareDate := NormalizeDate(date)
parsedIndexdate, err := time.Parse(DateFormat, indexDate)
if err != nil {
log.Error("Error while parsing date", zap.Error(err))
return EMPTY
}
parsedCompareDate, err := time.Parse(DateFormat, compareDate)
if err != nil {
log.Error("Error while parsing date", zap.Error(err))
return EMPTY
}
if parsedIndexdate.Before(parsedCompareDate) {
return case1
}
return case2
}