|
@@ -2305,3 +2305,37 @@ func GetQuarterStrStartDatesInRange(startTimeStr, endTimeStr string) (quartersSt
|
|
|
quartersStar = strings.Join(quarters, "+")
|
|
|
return quartersStar, nil
|
|
|
}
|
|
|
+
|
|
|
+// 通过开始时间,结束时间,获取对应季度的拼接字符串 为啥一样的代码要写两遍,因为产品有的地方要求展示 2024Q1有的地方要求展示24Q1
|
|
|
+func GetQuarterStrStartDatesInRangeHaveYear(startTimeStr, endTimeStr string) (quartersStar string, err error) {
|
|
|
+ startTime, err := time.Parse("2006-01-02", startTimeStr)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ endTime, err := time.Parse("2006-01-02", endTimeStr)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ adjustedStartTime := startTime.AddDate(0, -int(startTime.Month()-1)%3, -startTime.Day()+1)
|
|
|
+
|
|
|
+ startYear, _, _ := adjustedStartTime.Date()
|
|
|
+ endYear, _, _ := endTime.Date()
|
|
|
+
|
|
|
+ var quarters []string
|
|
|
+ for year := startYear; year <= endYear; year++ {
|
|
|
+ for quarter := 1; quarter <= 4; quarter++ {
|
|
|
+ firstMonth := (quarter-1)*3 + 1
|
|
|
+ quarterStartDate := time.Date(year, time.Month(firstMonth), 1, 0, 0, 0, 0, time.UTC)
|
|
|
+ if quarterStartDate.After(endTime) || quarterStartDate.AddDate(0, 3, -1).Before(adjustedStartTime) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ quartersYear := quarterStartDate.Year()
|
|
|
+ yearStr := strconv.Itoa(quartersYear)
|
|
|
+ quarters = append(quarters, fmt.Sprint(yearStr, "Q", quarter))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ quartersStar = strings.Join(quarters, ",")
|
|
|
+ return quartersStar, nil
|
|
|
+}
|