Skip to content

Commit 1e5dc4b

Browse files
committed
处理时区问题
1 parent 2aa21eb commit 1e5dc4b

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ docker:
1414
docker build -t cloudcat .
1515

1616
docker-test:
17-
docker run -it -v $(PWD)/bilibili.zip:/cloudcat/bilibili.zip $(REMOTE_REPO) exec bilibili.zip
17+
docker run -it -v $(PWD)/bilibili.zip:/cloudcat/bilibili.zip -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone $(REMOTE_REPO) exec bilibili.zip
1818

1919
docker-push: docker
2020
docker tag cloudcat $(REMOTE_REPO)

cmd/scriptcat/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
)
77

88
func main() {
9-
109
rootCmd := &cobra.Command{
1110
Use: "scriptcat",
1211
}

pkg/scriptcat/option.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package scriptcat
33
import (
44
"context"
55
"net/http"
6+
"time"
67

78
"github.com/sirupsen/logrus"
89
)
910

1011
type Options struct {
1112
context.Context
1213
cookieJar http.CookieJar
14+
location *time.Location
1315
_log func(level logrus.Level, format string, args ...interface{})
1416
}
1517

@@ -38,3 +40,9 @@ func (o *Options) log(level logrus.Level, format string, args ...interface{}) {
3840
o._log(level, format, args)
3941
}
4042
}
43+
44+
func WithLocation(loc *time.Location) Option {
45+
return func(opts *Options) {
46+
opts.location = loc
47+
}
48+
}

pkg/scriptcat/scriptcat.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"strings"
7+
"time"
78

89
"github.com/robfig/cron/v3"
910
"github.com/scriptscat/cloudcat/pkg/executor"
@@ -23,7 +24,9 @@ func NewScriptCat() (*ScriptCat, error) {
2324
}
2425

2526
func (s *ScriptCat) options(opt ...Option) *Options {
26-
options := &Options{}
27+
options := &Options{
28+
location: time.Local,
29+
}
2730
for _, o := range opt {
2831
o(options)
2932
}
@@ -42,7 +45,7 @@ func (s *ScriptCat) Run(ctx context.Context, script string, opt ...Option) (stri
4245
opts.log(logrus.InfoLevel, "start run script")
4346
return s.runOnce(ctx, exec, code)
4447
}
45-
cron := cron.New(cron.WithSeconds())
48+
cron := cron.New(cron.WithSeconds(), cron.WithLocation(opts.location))
4649
unit := strings.Split(c[0], " ")
4750
if len(unit) == 5 {
4851
unit = append([]string{"0"}, unit...)

0 commit comments

Comments
 (0)