Fix: Reset-AutomationSchedules incorrectly checking if provided time is at least one hour in the future #1834
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🛠️ Description
This fixes an issue in the validation of the provided time in Reset-AutomationSchedules.ps1. The current implementation was checking UTC - 1 hour against the local time of the parsed time string instead of UTC. The current implementation was also checking if sooner than an hour ago instead of sooner than an hour in the future.
Output of the original script from when I encountered the bug:
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: 2025-10-02 06:00:00
Exception: C:\Working\finops-toolkit\src\optimization-engine\Reset-AutomationSchedules.ps1:90
Line |
90 | throw "$newBaseTimeStr is an invalid base time. It can't be s …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 2025-10-02 06:00:00Z is an invalid base time. It can't be sooner than 2025-10-02 02:56:01Z
📋 Checklist
🔬 How did you test this change?
🙋♀️ Do any of the following that apply?
📑 Did you update
docs/changelog.md
?📖 Did you update documentation?