|
@@ -959,3 +959,41 @@ func GetDaysBetween2Date(format, date1Str, date2Str string) (int, error) {
|
|
|
//计算相差天数
|
|
|
return int(date1.Sub(date2).Hours() / 24), nil
|
|
|
}
|
|
|
+
|
|
|
+// 通过开始时间,结束时间,获取对应季度的拼接字符串
|
|
|
+func GetQuarterStrStartDatesInRange(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
|
|
|
+ //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)
|
|
|
+ yearStr = yearStr[len(yearStr)-2:]
|
|
|
+
|
|
|
+ quarters = append(quarters, fmt.Sprint(yearStr, "Q", quarter))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ quartersStar = strings.Join(quarters, "+")
|
|
|
+ return quartersStar, nil
|
|
|
+}
|