Convert AtTime back to time.Time #805
-
Hello everyone, sorry if this is a dumb question, but is there any way to convert a AtTime type back to a time.Time type? The situation is the following: type Config struct {
times gocron.AtTimes
weekdays gocron.Weekdays
} Now I want to return the times and weekdays as a json object, therefore I need to convert the AtTime from the AtTimes back to time.Time. type atTime struct {
hours, minutes, seconds uint
}
func (a atTime) time(location *time.Location) time.Time {
return time.Date(0, 0, 0, int(a.hours), int(a.minutes), int(a.seconds), 0, location)
}
// AtTime defines a function that returns the internal atTime
type AtTime func() atTime
// NewAtTime provide the hours, minutes and seconds at which
// the job should be run
func NewAtTime(hours, minutes, seconds uint) AtTime {
return func() atTime {
return atTime{hours: hours, minutes: minutes, seconds: seconds}
}
}
// AtTimes define a list of AtTime
type AtTimes func() []AtTime This is sort of what I want to do: func reverseParseTimes(atTimes gocron.AtTimes) []string {
var times []string
for _, atTimeFunc := range atTimes() {
atTime := atTimeFunc()
location, _ := time.LoadLocation("UTC")
timeStr := atTime.time(location).Format("15:04:05")
times = append(times, timeStr)
}
return times
} Is the functionality of converting AtTimes back something that is missing or am I missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@Nikurasuu how does this look? #806 |
Beta Was this translation helpful? Give feedback.
@Nikurasuu how does this look? #806