|
@@ -22,9 +22,9 @@ import (
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- TimeV1 = regexp.MustCompile("(\\d{4})[年.]?$")
|
|
|
- TimeV2 = regexp.MustCompile("(\\d{4}[年.\\-/]?)(\\d{1,2}[月.\\-/]?$)")
|
|
|
- TimeV3 = regexp.MustCompile("(\\d{4}[年.\\-/]?)(\\d{1,2}[月.\\-/]?)(\\d{1,2}日?$)")
|
|
|
+ TimeV1 = regexp.MustCompile("^(\\d{4})[年.]?$")
|
|
|
+ TimeV2 = regexp.MustCompile("^(\\d{4})[年./-]?(\\d{1,2})[月./-]?$")
|
|
|
+ TimeV3 = regexp.MustCompile("^(\\d{4})[年./-]?(\\d{1,2})[月./-]?(\\d{1,2})[日]?$")
|
|
|
TimeClear = regexp.MustCompile("[年|月|日|/|.|-]")
|
|
|
filterSpace = regexp.MustCompile("<[^>]*?>|[\\s\u3000\u2003\u00a0]")
|
|
|
date1 = regexp.MustCompile("20[0-2][0-9][年|\\-/.][0-9]{1,2}[月|\\-/.][0-9]{1,2}[日]?")
|
|
@@ -607,6 +607,7 @@ func GetEsField(tmp map[string]interface{}, stype string) (map[string]interface{
|
|
|
// @Description 采购意向 预计采购时间处理
|
|
|
// @Author J 2022/6/7 8:04 PM
|
|
|
func getMethod(str string) int64 {
|
|
|
+ // Handle "YYYY" format
|
|
|
if TimeV1.MatchString(str) {
|
|
|
arr := TimeV1.FindStringSubmatch(str)
|
|
|
st := arr[1] + "0000"
|
|
@@ -614,28 +615,44 @@ func getMethod(str string) int64 {
|
|
|
if err == nil {
|
|
|
return parseInt
|
|
|
}
|
|
|
- } else if TimeV2.MatchString(str) {
|
|
|
+ }
|
|
|
+
|
|
|
+ // Handle "YYYYMM" or "YYYY/MM" or "YYYY-MM" or "YYYY.MM" format
|
|
|
+ if TimeV2.MatchString(str) {
|
|
|
arr := TimeV2.FindStringSubmatch(str)
|
|
|
- str1 := arr[2]
|
|
|
- if len(str1) == 1 {
|
|
|
- str1 = "0" + str1
|
|
|
+ year := arr[1]
|
|
|
+ month := arr[2]
|
|
|
+ if len(month) == 1 {
|
|
|
+ month = "0" + month
|
|
|
}
|
|
|
- str2 := TimeClear.ReplaceAllString(arr[1], "") + TimeClear.ReplaceAllString(str1, "") + "00"
|
|
|
+ str2 := year + month + "00"
|
|
|
parseInt, err := strconv.ParseInt(str2, 10, 64)
|
|
|
if err == nil {
|
|
|
return parseInt
|
|
|
}
|
|
|
- } else if TimeV3.MatchString(str) {
|
|
|
+ }
|
|
|
+
|
|
|
+ // Handle "YYYYMMDD" or "YYYY/MM/DD" or "YYYY-MM-DD" or "YYYY.MM.DD" format
|
|
|
+ if TimeV3.MatchString(str) {
|
|
|
match := TimeV3.FindStringSubmatch(str)
|
|
|
if len(match) >= 4 {
|
|
|
- year, _ := strconv.Atoi(match[1])
|
|
|
- month, _ := strconv.Atoi(match[2])
|
|
|
- day, _ := strconv.Atoi(match[3])
|
|
|
-
|
|
|
- dateInt64 := int64(year*10000 + month*100 + day)
|
|
|
- return dateInt64
|
|
|
+ year := match[1]
|
|
|
+ month := match[2]
|
|
|
+ day := match[3]
|
|
|
+ if len(month) == 1 {
|
|
|
+ month = "0" + month
|
|
|
+ }
|
|
|
+ if len(day) == 1 {
|
|
|
+ day = "0" + day
|
|
|
+ }
|
|
|
+ dateStr := year + month + day
|
|
|
+ parseInt, err := strconv.ParseInt(dateStr, 10, 64)
|
|
|
+ if err == nil {
|
|
|
+ return parseInt
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return 0
|
|
|
}
|
|
|
|