From 80860657794e9965434bb9a591883fba96c87d67 Mon Sep 17 00:00:00 2001 From: chinhnc Date: Fri, 10 Nov 2023 23:07:12 +0700 Subject: [PATCH] Exposing job's scheduled unit and interval (#606) * Added String() function to schedulingUnit * Exposed job's unit and interval * ScheduledUnit() returns string instead of schedulingUnit * Gofumpted --- gocron.go | 4 ++++ job.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/gocron.go b/gocron.go index def4383d..a1584173 100644 --- a/gocron.go +++ b/gocron.go @@ -90,6 +90,10 @@ const ( crontab ) +func (s schedulingUnit) String() string { + return [...]string{"milliseconds", "seconds", "minutes", "hours", "days", "weeks", "months", "duration", "crontab"}[s] +} + func callJobFunc(jobFunc interface{}) { if jobFunc == nil { return diff --git a/job.go b/job.go index 13f01979..76ab356a 100644 --- a/job.go +++ b/job.go @@ -446,6 +446,16 @@ func (j *Job) ScheduledTime() time.Time { return j.nextRun } +// ScheduledUnit returns the scheduled unit of the Job. +func (j *Job) ScheduledUnit() string { + return j.unit.String() +} + +// Interval returns the scheduled interval of the Job. +func (j *Job) ScheduledInterval() int { + return j.interval +} + // ScheduledAtTime returns the specific time of day the Job will run at. // If multiple times are set, the earliest time will be returned. func (j *Job) ScheduledAtTime() string {