瀏覽代碼

指标期数位移-bug修改

gmy 6 月之前
父節點
當前提交
b5490f71da
共有 1 個文件被更改,包括 21 次插入20 次删除
  1. 21 20
      utils/common.go

+ 21 - 20
utils/common.go

@@ -1492,36 +1492,37 @@ func IsDivideZero(err error) bool {
 
 // CalculateTradingDays 计算天数 跳过周末
 func CalculateTradingDays(baseDate time.Time, tradingDays int, resultMap map[string]float64, moveType int) int {
-	totalDays := 0
+	oldDate := baseDate
 
-	for tradingDays > 0 {
-		// Move to the next day
-		var moveDays int
-		if moveType != 2 {
-			moveDays = 1
-		} else {
-			moveDays = -1
-		}
+	// Move to the next day
+	var moveDays int
+	if moveType != 2 {
+		moveDays = tradingDays
+	} else {
+		moveDays = -tradingDays
+	}
 
-		baseDate = baseDate.AddDate(0, 0, moveDays)
+	baseDate = baseDate.AddDate(0, 0, moveDays)
 
-		format := baseDate.Format(FormatDate)
+	/*format := baseDate.Format(FormatDate)
 
-		if _, isHoliday := resultMap[format]; isHoliday {
-			totalDays++
-			continue
-		}
+	if _, isHoliday := resultMap[format]; isHoliday {
+		totalDays++
+		continue
+	}*/
 
+	for {
 		weekday := baseDate.Weekday()
-
-		// Skip weekends (Saturday and Sunday)
 		if weekday != time.Saturday && weekday != time.Sunday {
-			tradingDays--
+			break // 如果是工作日,退出循环
 		}
-		totalDays++
+		baseDate = baseDate.AddDate(0, 0, 1) // 向前移动一天
 	}
+	subDays := baseDate.Sub(oldDate)
+
+	days := int(math.Abs(subDays.Hours() / 24))
 
-	return totalDays
+	return days
 }
 
 // getLastDayOfMonth 获取某个月的最后一天