MCPcopy Create free account
hub / github.com/codnect/chrono / NextExecutionTime

Method NextExecutionTime

trigger.go:67–107  ·  view source on GitHub ↗
(ctx TriggerContext)

Source from the content-addressed store, hash-verified

65}
66
67func (trigger *CronTrigger) NextExecutionTime(ctx TriggerContext) time.Time {
68 now := time.Now()
69 lastCompletion := ctx.LastCompletionTime()
70
71 if !lastCompletion.IsZero() {
72
73 lastExecution := ctx.LastTriggeredExecutionTime()
74
75 if !lastExecution.IsZero() && now.Before(lastExecution) {
76 now = lastExecution
77 }
78
79 }
80
81 originalLocation := now.Location()
82
83 convertedTime := now.In(trigger.location)
84 convertedTime = time.Date(convertedTime.Year(),
85 convertedTime.Month(),
86 convertedTime.Day(),
87 convertedTime.Hour(),
88 convertedTime.Minute(),
89 convertedTime.Second(),
90 convertedTime.Nanosecond(),
91 trigger.location)
92
93 next := trigger.cronExpression.NextTime(convertedTime)
94
95 // there is a bug causes timezone changing when an operation is performed on time value like add, subtraction
96 // to resolve this issue, we use a workaround solution
97 next = time.Date(next.Year(),
98 next.Month(),
99 next.Day(),
100 next.Hour(),
101 next.Minute(),
102 next.Second(),
103 next.Nanosecond(),
104 trigger.location)
105
106 return next.In(originalLocation)
107}

Callers

nothing calls this directly

Calls 3

NextTimeMethod · 0.80
LastCompletionTimeMethod · 0.65

Tested by

no test coverage detected