From ddb36b5aa703ec3d4bd9ce279b00e082616b61e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E7=BA=AF=E5=87=80?= <1113655791@qq.com> Date: Wed, 26 Feb 2025 21:40:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Workday=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95RangeDesc,=E7=94=A8=E4=BA=8E=E9=81=8D=E5=8E=86?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=B7=A5=E4=BD=9C=E6=97=A5,=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=B9=B3=E5=AE=89=E9=93=B6=E8=A1=8C=E7=9A=84=E6=97=A5?= =?UTF-8?q?=E7=BA=BF=E6=95=B0=E6=8D=AE,=E4=BD=86=E6=98=AF=E8=BF=98?= =?UTF-8?q?=E6=9C=89=E6=AF=94=E5=B9=B3=E5=AE=89=E9=93=B6=E8=A1=8C=E6=9B=B4?= =?UTF-8?q?=E6=97=A9=E4=B8=8A=E5=B8=82=E7=9A=84=E5=85=AC=E5=8F=B8,?= =?UTF-8?q?=E4=BC=9A=E6=9C=89=E4=BA=9B=E8=AF=AF=E5=B7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workday.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/workday.go b/workday.go index e393600..7668675 100644 --- a/workday.go +++ b/workday.go @@ -4,7 +4,6 @@ import ( _ "github.com/glebarez/go-sqlite" "github.com/injoyai/base/maps" "github.com/injoyai/logs" - "github.com/robfig/cron/v3" "os" "path/filepath" "time" @@ -60,6 +59,7 @@ type Workday struct { // Update 更新 func (this *Workday) Update() error { //获取平安银行的日K线,用作历史是否节假日的判断依据 + //但是平安银行上市时间是1991年4月3日,交易所成立时间是1990年12月1号,会有误差 //判断日K线是否拉取过 //获取全部工作日 @@ -110,6 +110,21 @@ func (this *Workday) TodayIs() bool { return this.Is(time.Now()) } +// RangeDesc 倒序遍历工作日,从今天-1990年12月(深圳交易所成立时间) +func (this *Workday) RangeDesc(f func(t time.Time) bool) { + t := IntegerDay(time.Now()) + for ; t.Before(time.Date(1990, 12, 1, 0, 0, 0, 0, time.Local)); t = t.Add(-time.Hour * 24) { + if t.Weekday() == time.Saturday || t.Weekday() == time.Sunday { + continue + } + if this.Is(t) { + if !f(t) { + return + } + } + } +} + // WorkdayModel 工作日 type WorkdayModel struct { ID int64 `json:"id"` //主键