AutoShutdownSchedule icon indicating copy to clipboard operation
AutoShutdownSchedule copied to clipboard

Days of the Week evaluated as UTC and not the configured Time Zone

Open aclarkot opened this issue 2 years ago • 7 comments
trafficstars

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:

  1. Enable the autoshutdownschedule runbook
  2. Set a custom time zone using the TZ parameter
  3. 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.

aclarkot avatar Mar 16 '23 00:03 aclarkot

Hello aclarkot,

Thanks for reporting, what version of the script are you running? Make sure you test with the latest, 3.9.0.

Regards, Tomas

tomasrudh avatar Mar 16 '23 07:03 tomasrudh

I've tested with 3.9.0 and 3.9.2, the behavior is the same with both.

The workaround I implemented above is resolving the issue in my case. So, the script doesn't evaluate 'day of the week' with the correct time zone, it only uses UTC.

aclarkot avatar Mar 20 '23 03:03 aclarkot

Could you please share your configuration, your variables and the tag.

Thanks!

Tomas

From: Aidan Clark @.> Sent: Monday, 20 March 2023 04:36 To: tomasrudh/AutoShutdownSchedule @.> Cc: Tomas Rudh @.>; Comment @.> Subject: Re: [tomasrudh/AutoShutdownSchedule] Days of the Week evaluated as UTC and not the configured Time Zone (Issue #20)

Using 3.9.2 but the behavior is the same with 3.9.0.

— Reply to this email directly, view it on GitHub https://u20788398.ct.sendgrid.net/ls/click?upn=27HVtNwUduq3wZxogItvUavRPk72rrR-2Flm3jQ4-2F0sysqz0HjrVfYKX41J30UjcPl9TvcjGdZVd4-2BMQM43-2FQkhCjHTpqrSDv1bx5oLFyi6l3s1A6lpEJmyOEPXrHJ2ZH-2BJ35q_U31jt5HgHBh7k3Grc5s4l12WFyC7wWKNO2GJZxWPjPqkF6PWDhwbWwvxwkh8o-2Br-2B9qjpwWY-2Byvyu-2BseJFheSOOfLGmWC0kPTzi0a0xIuAwa7EK1W0jfRgrQqHZCkKb2RLMQfatO1l2eB3ZrnFibwjWF-2F8mB9Tlo5tkJAsScdHnxxLeKPRVaAnsXADjHxwfiaE-2FaCQQ5oXj2PaFwsDaKppnH-2Fhe2pu2to42X4Ya0QRjh0hl765vROGam5i6wFGT9K9NevQ59X6yZqqcfBEaf-2F4A-3D-3D , or unsubscribe https://u20788398.ct.sendgrid.net/ls/click?upn=27HVtNwUduq3wZxogItvUVgmFDSuRkRUP0hiwX-2BQZOpCh6EjzUnAHvTmZkOI0ibXSUbdLYTXr-2BnFr7nZWc5BaCN7gETPJcu9lv-2Fgv7aqGyLlcllMvmhu8-2BD-2BiNpd2r04PInlxsQMCdxV2wYBgAQqDw-3D-3DPQHc_U31jt5HgHBh7k3Grc5s4l12WFyC7wWKNO2GJZxWPjPqkF6PWDhwbWwvxwkh8o-2Br-2B9qjpwWY-2Byvyu-2BseJFheSOOfLGmWC0kPTzi0a0xIuAwa7EK1W0jfRgrQqHZCkKb2RG-2B-2FA3BR8PGIWCXNbjGVL8lUIwJJMzR0W9vjVRIYWBRtQzmBznMu6O4jYPVAgWOjQ7aWaZJe0Ca-2BBDutidBxC3ynrogVaAbOIoJIGjiDuX43T06Gz8yXtfoyIyUGvMoKhcd0FGNdfAG9Md0Ppm3uYEQ-3D-3D . You are receiving this because you commented. https://u20788398.ct.sendgrid.net/ls/click?upn=27HVtNwUduq3wZxogItvUVgmFDSuRkRUP0hiwX-2BQZOqniRk4OQu-2FvcxQxftUVPZdAFY82vzDCsZtE8bNgVD0ZHxCVlAGIZ5lecwVBtAVz7hiOV2tc5tEOl9DIa2h5HSZBCpr-2F2z6HwKczKbcoK0ncInbXbeBbQ8UZIzqtLfjBj47KiWvHUaHoMUDHjGC60Jt3tPE3-2B8s4qODMA5VYb3OmjmqMhZjm96aUQHPqKLEZa0-3DNeIF_U31jt5HgHBh7k3Grc5s4l12WFyC7wWKNO2GJZxWPjPqkF6PWDhwbWwvxwkh8o-2Br-2B9qjpwWY-2Byvyu-2BseJFheSOOfLGmWC0kPTzi0a0xIuAwa7EK1W0jfRgrQqHZCkKb2Rt4LUytM-2BpVeqznNCZxo21hkIgOaPxjX3rO9-2FLZLeRz0zG1bQwpsZIlRb2c-2BSt8prZ6hQ5FUH3NhJ7IbWkpBpzL2pmvaj7dMW-2FxWp4YRRnDL6Gb8VrSNFOVobTDqLZUiY-2BuSV07Uk8SerxVug5kRtGQ-3D-3D Message ID: @.*** @.***> >

tomasrudh avatar Mar 23 '23 18:03 tomasrudh

Schedule Configuration: image Automation Account Variables: image Example Job Output from testing (VM should shutdown on Thursday): image

aclarkot avatar Mar 23 '23 23:03 aclarkot

Hi,

This is unfortunate, it seems the certificate on the site where the pictures are saved has expired, so I can’t see them.

https://u20788398.ct.sendgrid.net/ls/click?upn=27HVtNwUduq3wZxogItvUfffY9L-2B4DOq5QI-2BGLuZSH96TDnPGR8OxtKbYjU9C7duwKO7qNRuZwrS-2BKKU-2BLSjGuxoZfEEpA3QT2SYfzd8OcS9ku7wYrpGXBiSXg6evsI4dRfmomjvlwTzJeWeVUCNAW5kwDOTPNdmd-2FxJOr7Q22s-3D26AJ_U31jt5HgHBh7k3Grc5s4l2WU7RQ9sLirjyVZ4Ygay-2FTK6zY4zLj99GlVksSxLZPBUsSOz7gcdiGqBVEP0J-2FxX3hN2WCVM-2FVKO8nkUgZ38HGf6fKnM4-2Bap1yE2lNkAIz4HSGNZknXnNT02b0g81CbxYhpgDWgWw2xmcvwaa69BXeBY20SvnJ4hS6dK3XkB8aVT559uSRVf3ll-2Fc4HFCRjRMZIXNC5nKQI0c-2BJA56LckiFttQq2z5OQsj-2BVy89mxK7xXH6ljkN-2BjASp6WFEoaUbg-3D-3D

I assume they will fix that shortly, otherwise you can send them to me in email: tomas @ rudhs.se.

Regards,

Tomas

From: Aidan Clark @.> Sent: Friday, 24 March 2023 00:45 To: tomasrudh/AutoShutdownSchedule @.> Cc: Tomas Rudh @.>; Comment @.> Subject: Re: [tomasrudh/AutoShutdownSchedule] Days of the Week evaluated as UTC and not the configured Time Zone (Issue #20)

Schedule Configuration: https://u20788398.ct.sendgrid.net/ls/click?upn=27HVtNwUduq3wZxogItvUfffY9L-2B4DOq5QI-2BGLuZSH96TDnPGR8OxtKbYjU9C7duwKO7qNRuZwrS-2BKKU-2BLSjGoL4f9-2BCoVYfUT3fT7owpObt8stKmka4o2VoyNhdMeq4iw6zwVa-2BLr147CvVh6TY3A-3D-3DUSMY_U31jt5HgHBh7k3Grc5s4l2WU7RQ9sLirjyVZ4Ygay-2FTK6zY4zLj99GlVksSxLZPBUsSOz7gcdiGqBVEP0J-2FxX3hN2WCVM-2FVKO8nkUgZ38HGf6fKnM4-2Bap1yE2lNkAIz4wT-2FuDea0WLvhQ9oFsZoyuItkFLPUCCVfGswHD3ky4Y3v3UTJTpfFu-2FkNc1-2FUOHGvE6QQUXpNq0q0-2F2O9NY3qRlGQ75P688sItL5SoPTfApx-2BDgVGVNO8w-2F1ipHOyQZ4SHUASthzO55wYVXqMCZ1mSw-3D-3D Automation Account Variables: https://u20788398.ct.sendgrid.net/ls/click?upn=27HVtNwUduq3wZxogItvUfffY9L-2B4DOq5QI-2BGLuZSH96TDnPGR8OxtKbYjU9C7duwKO7qNRuZwrS-2BKKU-2BLSjGjkejvw9riqL6S0sJUs044SGk5hCvYobGWO4WRxeVoxtOHhEjHSXSZPO390VDCJlxw-3D-3DXCt3_U31jt5HgHBh7k3Grc5s4l2WU7RQ9sLirjyVZ4Ygay-2FTK6zY4zLj99GlVksSxLZPBUsSOz7gcdiGqBVEP0J-2FxX3hN2WCVM-2FVKO8nkUgZ38HGf6fKnM4-2Bap1yE2lNkAIz4beUShYQ1Dpr5ntzrnYeHlbfd-2FlyGgKb06EEo-2Fumd6p2PrylouRj8fTbdYJ1Z10D0C8JIyUwOB5Z0J9hKr9cASzz0-2BZ5-2Bruky9qtVnvXC6Gfhz4vQu-2B3oVdzVF8uv0-2B5HFrN74puC5YePtUUxq-2BZlUw-3D-3D Example Job Output from testing (VM should shutdown on Thursday): https://u20788398.ct.sendgrid.net/ls/click?upn=27HVtNwUduq3wZxogItvUfffY9L-2B4DOq5QI-2BGLuZSH96TDnPGR8OxtKbYjU9C7duwKO7qNRuZwrS-2BKKU-2BLSjGuxoZfEEpA3QT2SYfzd8OcS9ku7wYrpGXBiSXg6evsI4qjym76emmqBM9uNa01DcMg-3D-3Deg8p_U31jt5HgHBh7k3Grc5s4l2WU7RQ9sLirjyVZ4Ygay-2FTK6zY4zLj99GlVksSxLZPBUsSOz7gcdiGqBVEP0J-2FxX3hN2WCVM-2FVKO8nkUgZ38HGf6fKnM4-2Bap1yE2lNkAIz4PQT1X9rtw-2BcbklR6aejoDUS6iSujhPNb89R3-2F95RhRg-2FWWszHWRIQow-2BYqJGYYSAvuHoXhjSluW4U1eNO0Wl0Y-2BuVyj9cBstRXhGLyE4qwNuGxaGBGNdZ4ikyPlRG1r25tLzWmSa-2BX366RaX0GCFWg-3D-3D

— Reply to this email directly, view it on GitHub https://u20788398.ct.sendgrid.net/ls/click?upn=27HVtNwUduq3wZxogItvUavRPk72rrR-2Flm3jQ4-2F0sysqz0HjrVfYKX41J30UjcPl9TvcjGdZVd4-2BMQM43-2FQkhCjHTpqrSDv1bx5oLFyi6l1iu1DXzSvDpgCDCPu4B97dJWwd_U31jt5HgHBh7k3Grc5s4l2WU7RQ9sLirjyVZ4Ygay-2FTK6zY4zLj99GlVksSxLZPBUsSOz7gcdiGqBVEP0J-2FxX3hN2WCVM-2FVKO8nkUgZ38HGf6fKnM4-2Bap1yE2lNkAIz4jqmA2ypmy4ZfNU9-2Bm8sozBcNtwDqSMAdPJ8YdqKoGirn2b-2BsTBCS1YD23F0lv3pIsN9wqhuBUWCGBpD9vRUSNlj0I3z212UsZrrw4zH8akunUse3E5we1BNquX7tHC8huwj8IJp2aFEU-2B0L6ntkXig-3D-3D , or unsubscribe https://u20788398.ct.sendgrid.net/ls/click?upn=27HVtNwUduq3wZxogItvUVgmFDSuRkRUP0hiwX-2BQZOpCh6EjzUnAHvTmZkOI0ibXSUbdLYTXr-2BnFr7nZWc5BaOhyQ-2Fc-2F0TPCb3bujLM3FuhLUVdYN9GiiZAX0R-2B6cANf54tDNK4VrIvOldN0nOpWeQ-3D-3DIqUn_U31jt5HgHBh7k3Grc5s4l2WU7RQ9sLirjyVZ4Ygay-2FTK6zY4zLj99GlVksSxLZPBUsSOz7gcdiGqBVEP0J-2FxX3hN2WCVM-2FVKO8nkUgZ38HGf6fKnM4-2Bap1yE2lNkAIz4OWPSNAcC488aYf9xJi35zG2WlY6owizGPgPfq0wuCRwIR8uMS7SzQTnn2recWi3mwyhNWAjdlm0KLfBmHXx9fZg9tqjNl-2FDSLcsUYcxyYRbgP-2FkWKIhZjqKmVcNQhFvAm4CNaQmVil0FgVoK8eajdw-3D-3D . You are receiving this because you commented. https://u20788398.ct.sendgrid.net/ls/click?upn=27HVtNwUduq3wZxogItvUVgmFDSuRkRUP0hiwX-2BQZOqniRk4OQu-2FvcxQxftUVPZdLbJtBVaEqCo1yreIt7JnO8X1u2dqc1w4mzBYL4K0qLmgaYT0QHh0AKnDF-2Ba1k1Es-2BWAr26oUiQeJgN6PzN7clDB3t5sU4ZZIb8-2FbEyBCIouZ5OlpX7OoJduNSczPqSUGSJCnW7kEEI4TeiskujqveWuL-2F9yJXvCqLbLF69A-2B7vw-3DJiI__U31jt5HgHBh7k3Grc5s4l2WU7RQ9sLirjyVZ4Ygay-2FTK6zY4zLj99GlVksSxLZPBUsSOz7gcdiGqBVEP0J-2FxX3hN2WCVM-2FVKO8nkUgZ38HGf6fKnM4-2Bap1yE2lNkAIz4Yx44vQ0miQ1tu-2BMzVqZCy27PPdOC6yat-2BFAKyGJ-2BUuumyiojIjqKc3NAL4FVvs8CRyawLgcoVstbANBXuJQ1e9QcfkwASzxo-2BeEJsgHfY-2BYMQISQvUeAi-2B-2F7d3WHZ40hkZjzxc-2FGWfOvaHUQ9fC8pA-3D-3D Message ID: @.*** @.***> >

tomasrudh avatar Mar 24 '23 21:03 tomasrudh

Hi Tom, I was also going to report this error. Can I know if there is a fix for the same. Issue: When the tag contains days of the week, the logic validate the day ( Sunday or Monday etc) in UTC only, it is not using the Timezone present in the variable. Cheers, Siva

sivagithub25 avatar Jun 23 '23 00:06 sivagithub25

Hi @aclarkot and @tomasrudh,

I believe the code segment

if ($TimeRange -eq (Get-Date).DayOfWeek) { $parsedDay = Get-Date "00:00" }

Should be changed to

if ($TimeRange -eq [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId([DateTime]::Now,$tz).dayofweek) { $parsedDay = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId([DateTime]::Now,$tz).date }

Where ever the logic written by using Get-Date in the code, I think we need to consider using ConvertTimeBySystemTimeZoneId by passing the $tx variable.

@aclarkot , in your workaround, I believe $parsedDay = (Get-Date "00:00").Addhours(13) might have an issue. Because parseday variable is using to get the range for 24 hours of the day which needs to be start at 12:00 AM .

Cheers, Siva

sivagithub25 avatar Jun 23 '23 04:06 sivagithub25