chore: add weekday
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
kekskurse 2025-08-06 18:20:26 +02:00
parent 14cc0a7d6a
commit 5bbe5cedfe
2 changed files with 14 additions and 4 deletions

View file

@ -20,6 +20,7 @@ type jobconfig struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Hour string `yaml:"hour"` Hour string `yaml:"hour"`
Minute string `yaml:"minute"` Minute string `yaml:"minute"`
Weekday string `yaml:"weekday"`
Command string `yaml:"command"` Command string `yaml:"command"`
Notification string `yaml:"notification,omitempty"` Notification string `yaml:"notification,omitempty"`
} }
@ -65,6 +66,15 @@ func ReadFromFile(path string) (config, error) {
} }
func (jc jobconfig) MatchCurrentTime(t time.Time) (bool, error) { func (jc jobconfig) MatchCurrentTime(t time.Time) (bool, error) {
fmt.Println("weekday", jc.Weekday)
matchWeekDay, err := matchTime(jc.Weekday, int(t.Weekday()))
if err != nil {
return false, err
}
if !matchWeekDay {
return false, nil
}
matchHour, err := matchTime(jc.Hour, t.Hour()) matchHour, err := matchTime(jc.Hour, t.Hour())
if err != nil { if err != nil {
return false, err return false, err

View file

@ -146,25 +146,25 @@ func TestMatchJobTime(t *testing.T) {
}{ }{
{ {
name: "failed-houre", name: "failed-houre",
job: jobconfig{Hour: "15", Minute: "*"}, job: jobconfig{Hour: "15", Minute: "*", Weekday: "*"},
expRes: false, expRes: false,
expErrMsg: "", expErrMsg: "",
}, },
{ {
name: "failed-minute", name: "failed-minute",
job: jobconfig{Hour: "*", Minute: "46"}, job: jobconfig{Hour: "*", Minute: "46", Weekday: "*"},
expRes: false, expRes: false,
expErrMsg: "", expErrMsg: "",
}, },
{ {
name: "pass", name: "pass",
job: jobconfig{Hour: "*", Minute: "*"}, job: jobconfig{Hour: "*", Minute: "*", Weekday: "*"},
expRes: true, expRes: true,
expErrMsg: "", expErrMsg: "",
}, },
{ {
name: "failed-with-error", name: "failed-with-error",
job: jobconfig{Hour: "abs", Minute: "*"}, job: jobconfig{Hour: "abs", Minute: "*", Weekday: "*"},
expRes: false, expRes: false,
expErrMsg: "cant parse time pattern", expErrMsg: "cant parse time pattern",
}, },