review code.

This commit is contained in:
2026-04-17 14:50:34 +08:00
parent a0a6d6adaa
commit 592c8e31dd
15 changed files with 487 additions and 338 deletions

41
internal/logic/utils.go Normal file
View File

@@ -0,0 +1,41 @@
package logic
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
}