-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Not sure if you have upgraded to PS 7.2.0 yet but it has a code breaking change which affects your Write-Calendar.ps1 script.
The code breaking change has to do with when you call Get-Date -Uformat %u
Prior to PS 7.2.0 when the date was a Sunday then Get-Date -Uformat %u returned 0 and it used values of ( 0 -6 for Sunday - Saturday).
PS 7.2.0 now returns 7 for Sunday ( and has values 1-7 for Monday-Sunday).
MS did not even consistently make the change or update all the documentation.
For example:
[System.Enum]::getvalues([type][System.DayOfWeek]) | ForEach-Object { echo "$_ $($_.value__)" }
Still has values of 0-6 for Sunday - Saturday and returns 0 for Sunday
Here are some other examples between PS 7.1.5 and PS 7.2.0 but it should be noted that the PS 7.1.5 behavior is how it has been all the way back to Windows PowerShell 5.1. Also the issue occurs on both Windows PS 7.2.0 and Linux PS 7.2.0
ps 7.1.5
Get-Date 05/01/2022 -uformat %u # returns 0 - Correct
(Get-Date 05/01/2022).DayOfWeek # returns Sunday - Correct
[int](Get-Date 05/01/2022).DayOfWeek # returns 0 - Correct
ps 7.2.0
Get-Date 05/01/2022 -uformat %u # returns 7 - Wrong
(Get-Date 05/01/2022).DayOfWeek # returns Sunday - Correct
[int](Get-Date 05/01/2022).DayOfWeek # returns 0 - Correct
You use this the value to determine offsets when you print the month and year calendars.
I reported this bug to MS and they claim the change was on purpose and I have been discussing with them because in addition to breaking this code it creates issues for anything else that used Get-Date -uFormat %u and it creates an inconsistency in PS because list type items are zero based and not 1 based.
You can view my bug here as well as the discussion
Hope that is helpful too you.
Joe
- Updated to fix the URL I first posted which was wrong