-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Describe the bug
When you specify a tag that includes days of the week E.g., '18:00->07:00,Saturday,Sunday'. The time-range (18:00->-7:00) is correctly evaluated using the time zone configured in the TZ variable. However, the days of the week (Saturday, Sunday) ignore the time zone and are evaluated as UTC. In my case TZ is set to 'New Zealand Standard Time' (UTC+13) so this is a major issue, the VMs don't shutdown until 1PM on Saturday.
To Reproduce
Steps to reproduce the behavior:
- Enable the autoshutdownschedule runbook
- Set a custom time zone using the TZ parameter
- Add a tag to a VM including days of the week
Expected behavior
The VM should shutdown at 00:00 according to the time zone in TZ on the specified day.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
The problem code block is below. Notice that 'Get-Date' will always return UTC unless it is modified with Get-Date.AddHours(X).
# If specified as day of week, check if today
if ([System.DayOfWeek].GetEnumValues() -contains $TimeRange) {
if ($TimeRange -eq (Get-Date).DayOfWeek) {
$parsedDay = Get-Date "00:00"
}
I have hacked it to work for my scenario as below by adding 13 hours for NZST.
# If specified as day of week, check if today
if ([System.DayOfWeek].GetEnumValues() -contains $TimeRange) {
if ($TimeRange -eq ((Get-Date).AddHours(13)).DayOfWeek) {
$parsedDay = (Get-Date "00:00").Addhours(13)
}
A proper solution is needed to always adjust Get-Date output according to the UTC offset required by the configured time zone.