in a StartTime = 0, EndTime = 0, Duration = 604800, cron = “0 0 * * 1“ settings, it will not correctly making the startActiveUnix and endActiveUnix as 1 week apart. After some investigation I found the calculation logic in the core_tournament.go’s calculateTournamentDeadlines() function forgot to add .UTC() in two places.
the correct version should be:
func calculateTournamentDeadlines(startTime, endTime, duration int64, resetSchedule *cronexpr.Expression, t time.Time) (startActiveTimeSec, endActiveTimeSec, expiryTimeSec int64) {
tUnix := t.UTC().Unix()
if resetSchedule != nil {
var startActiveUnix int64
if tUnix < startTime {
// the supplied time is behind the start time
startActiveUnix = resetSchedule.Next(time.Unix(startTime, 0).UTC()).UTC().Unix()
} else {
// check if we are landing squarely on the reset schedule
landsOnSched := resetSchedule.Next(t.UTC().Add(-1*time.Second)).Unix() == t.Unix()
if landsOnSched {
startActiveUnix = tUnix
} else {
startActiveUnix = resetSchedule.Last(t.UTC()).UTC().Unix()
}
}
// endActiveUnix is when the current iteration ends.
endActiveUnix := startActiveUnix + duration
// expiryUnix represent the start of the next schedule, i.e., when the next iteration begins. It's when the current records "expire".
expiryUnix := resetSchedule.Next(time.Unix(startActiveUnix, 0).UTC()).UTC().Unix()
if endActiveUnix > expiryUnix {
// Cap the end active to the same time as the expiry.
endActiveUnix = expiryUnix
}
if startTime > endActiveUnix {
// The start time after the end of the current active period but before the next reset.
// e.g. Reset schedule is daily at noon, duration is 1 hour, but time is currently 3pm.
schedules := resetSchedule.NextN(time.Unix(startTime, 0).UTC(), 2)
startActiveUnix = schedules[0].UTC().Unix()
endActiveUnix = startActiveUnix + duration
expiryUnix = schedules[1].UTC().Unix()
if endActiveUnix > expiryUnix {
// Cap the end active to the same time as the expiry.
endActiveUnix = expiryUnix
}
} else if startTime > startActiveUnix {
startActiveUnix = startTime
}
if endTime > 0 && expiryUnix > endTime {
expiryUnix = endTime
if endActiveUnix > expiryUnix {
// Cap the end active to the same time as the expiry.
endActiveUnix = expiryUnix
}
}
return startActiveUnix, endActiveUnix, expiryUnix
}
endActiveUnix := startTime + duration
expiryUnix := endTime
if endTime > 0 && endActiveUnix > endTime {
// Cap the end active to the same time as the expiry.
endActiveUnix = endTime
}
return startTime, endActiveUnix, expiryUnix
}
Adding this two UTC() would make the calculation becomes correct.