Skip to content

Commit

Permalink
fix: update go tests for scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgriffing committed Feb 25, 2024
1 parent 36876d8 commit b413014
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 56 deletions.
32 changes: 13 additions & 19 deletions clients/go/pkg/internal/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ func IsScheduleActive(schedule Schedule, scheduleType ScheduleType) bool {

func IsScheduleActiveWithNow(schedule Schedule, scheduleType ScheduleType, now time.Time) bool {

nowMillis := now.UnixMilli()

switch scheduleType {
case EmptyScheduleType:
return true
Expand Down Expand Up @@ -42,7 +44,7 @@ func IsScheduleActiveWithNow(schedule Schedule, scheduleType ScheduleType, now t
time.UTC,
)

if !now.After(startOfStartDate) || !now.Before(endOfEndDate) {
if startOfStartDate.UnixMilli() > nowMillis || nowMillis > endOfEndDate.UnixMilli() {
return false
}

Expand All @@ -53,31 +55,23 @@ func IsScheduleActiveWithNow(schedule Schedule, scheduleType ScheduleType, now t
case NoneScheduleTimeType:
return true
case StartEndScheduleTimeType:
startDateTimestamp := time.Date(
startDate.Year(),
startDate.Month(),
startDate.Day(),
startTime.Hour(),
startTime.Minute(),
startTime.Second(),
startTime.Nanosecond(),
time.UTC,
).UnixMilli()

endDateTimestamp := time.Date(
startOfEndDate := time.Date(
endDate.Year(),
endDate.Month(),
endDate.Day(),
endTime.Hour(),
endTime.Minute(),
endTime.Second(),
endTime.Nanosecond(),
0,
0,
0,
0,
time.UTC,
).UnixMilli()
)

nowTimestamp := now.UnixMilli()
startDateTimestampWithStartTime := startOfStartDate.UnixMilli() + schedule.StartTime
endDateTimestampWithEndTime := startOfEndDate.UnixMilli() + schedule.EndTime

return startDateTimestampWithStartTime <= nowMillis && nowMillis <= endDateTimestampWithEndTime

return nowTimestamp >= startDateTimestamp && nowTimestamp <= endDateTimestamp
case DailyScheduleTimeType:

zeroDay := time.UnixMilli(0).UTC()
Expand Down
Loading

0 comments on commit b413014

Please sign in to comment.