|
@@ -1492,36 +1492,37 @@ func IsDivideZero(err error) bool {
|
|
|
|
|
|
// CalculateTradingDays 计算天数 跳过周末
|
|
// CalculateTradingDays 计算天数 跳过周末
|
|
func CalculateTradingDays(baseDate time.Time, tradingDays int, resultMap map[string]float64, moveType int) int {
|
|
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()
|
|
weekday := baseDate.Weekday()
|
|
-
|
|
|
|
- // Skip weekends (Saturday and Sunday)
|
|
|
|
if weekday != time.Saturday && weekday != time.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 获取某个月的最后一天
|
|
// getLastDayOfMonth 获取某个月的最后一天
|