Skip to content

Commit eb6087b

Browse files
mpritchard2msbrettCopilot
authored
Fix: Reset-AutomationSchedules incorrectly checking if provided time is at least one hour in the future (#1834)
Co-authored-by: msbrett <msbrett@users.no-reply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ce22272 commit eb6087b

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/optimization-engine/Reset-AutomationSchedules.ps1

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,26 @@ else {
7777
$newBaseTimeStr = Read-Host "Please, enter a new base time for the *weekly* schedules in UTC (YYYY-MM-dd HH:mm:ss). If you want to keep the current one, just press ENTER"
7878
if (-not($newBaseTimeStr)) {
7979
$newBaseTimeStr = $baseTimeStr
80+
$baseTimeOffset = [DateTimeOffset]::Parse($newBaseTimeStr)
8081
}
8182
else {
83+
$minAllowedTime = [DateTimeOffset]::UtcNow.AddHours(1)
84+
8285
try {
83-
$newBaseTimeStr += "Z"
84-
$newBaseTime = [DateTime]::Parse($newBaseTimeStr)
86+
$baseTimeOffset = [DateTimeOffset]::Parse($newBaseTimeStr + "Z")
8587
}
8688
catch {
8789
throw "$newBaseTimeStr is an invalid base time. Use the following format: YYYY-MM-dd HH:mm:ss. For example: 1977-09-08 06:14:15"
8890
}
89-
if ($newBaseTime -lt (Get-Date).ToUniversalTime().AddHours(-1)) {
90-
throw "$newBaseTimeStr is an invalid base time. It can't be sooner than $((Get-Date).ToUniversalTime().AddHours(-1).ToString('u'))"
91+
92+
if ($baseTimeOffset -lt $minAllowedTime) {
93+
throw "$($baseTimeOffset.ToString('u')) is an invalid base time. It must be at least 1 hour in the future (after $($minAllowedTime.ToString('u')))"
9194
}
95+
96+
$newBaseTimeStr = $baseTimeOffset.ToString("yyyy-MM-dd HH:mm:ss") + "Z"
9297
}
9398

94-
$baseTimeUtc = [DateTime]::Parse($newBaseTimeStr).ToUniversalTime()
99+
$baseTimeUtc = $baseTimeOffset.UtcDateTime
95100

96101
if ($newBaseTimeStr -ne $baseTimeStr) {
97102
Write-Host "Updating current base schedule to every $($baseTimeUtc.DayOfWeek) at $($baseTimeUtc.TimeOfDay.ToString()) UTC..." -ForegroundColor Green
@@ -205,4 +210,4 @@ else
205210
Write-Host "Kept current Hybrid Worker option: $hybridWorkerOption" -ForegroundColor Green
206211
}
207212

208-
Write-Host "DONE" -ForegroundColor Green
213+
Write-Host "DONE" -ForegroundColor Green

0 commit comments

Comments
 (0)