Files
collector/internal/logic/utils.go

42 lines
1007 B
Go
Raw Normal View History

2026-04-17 14:50:34 +08:00
package logic
2026-04-17 13:08:48 +08:00
import (
"time"
)
// IsTradingTime 判断当前时间是否为A股交易时间
// A股交易时间
// - 工作日(周一至周五)
// - 上午9:30 - 11:30
// - 下午13:00 - 15:00
func IsTradingTime(t time.Time) bool {
// 检查是否为工作日1=周一, 5=周五)
weekday := t.Weekday()
if weekday == time.Saturday || weekday == time.Sunday {
return false
}
// 获取小时和分钟
hour := t.Hour()
minute := t.Minute()
// 转换为分钟数便于比较
currentMinutes := hour*60 + minute
// 上午交易时间9:30 - 11:30 (570 - 690分钟)
morningStart := 9*60 + 30 // 570
morningEnd := 11*60 + 30 // 690
// 下午交易时间13:00 - 15:00 (780 - 900分钟)
afternoonStart := 13 * 60 // 780
afternoonEnd := 15 * 60 // 900
// 判断是否在交易时间段内
if (currentMinutes >= morningStart && currentMinutes < morningEnd) ||
(currentMinutes >= afternoonStart && currentMinutes < afternoonEnd) {
return true
}
return false
}