29 lines
716 B
Go
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
|
|
}
|