-UFormat "%V" logic incorrect for 2021, counts based off calendar day instead of DOW
See original GitHub issueGetting the week number starts counting in 7 day increments on 1/1/2021 instead of following ISO standard of starting with Monday (if needed, full details in Wikipedia article and probably other locations).
Note: similar to 11534, closed fixed for 2020. Issue 4750 tracks a bunch of complaints with UFormat but is really old and doesn’t appear focused on a specific item. It’s hard to tell if this issue is being addressed by that item.
Steps to reproduce
(get-date 2020-12-31 -UFormat "%V")
(get-date 2021-01-01 -UFormat "%V")
(get-date 2021-01-08 -UFormat "%V")
Expected behavior
53
53
1
Actual behavior
53
1
2
Environment data
Name Value
---- -----
PSVersion 6.0.0
PSEdition Core
GitCommitId v6.0.0
OS Linux 3.10.0-693.11.6.el7.x86_64 #1 SMP Thu Jan 4 01:06:37 UTC 2018
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Get-Date -UFormat "%V" returns wrong weeknumber #11534
ReevesL mentioned this issue on Jan 8, 2021. -UFormat "%V" logic incorrect for 2021, counts based off calendar day instead of DOW #14584....
Read more >Java Calendar DAY_OF_WEEK SET to zero
Any out of range values are either normalized in lenient mode or detected as an invalid value in non-lenient mode.
Read more >What date does week 1 of 2021 start? - Claris Community
If you select 2 (Monday) as the starting day, then January 1 must be on Monday, Tuesday, Wednesday, or Thursday for that week...
Read more >Sort by Day of week - Microsoft Power BI Community
Solved: Hi when I chart some call volumes and also sales volumes I want to chart them by day of week. Meaning on...
Read more >DateTime - A date and time object for Perl
The DateTime module follows a simple logic for determining whether or not a given number is 0-based or 1-based. Month, day of month,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Got it, thanks. I saw that this was for PowerShell 6 and 7 issues. I see it’s fixed in 7 but not in 6. I’ll assume fixing 6 is no longer in play and close this. I’ll upgrade my Linux host from 6 to 7 and be a happy camper.
Thanks brianary & iSazonov.
While Windows PowerShell (
powershell.exe
) 5.1 (and earlier) erroneously returns2
forGet-Date 2021-01-08 -UFormat %V
, PowerShell Core (pwsh.exe
) 7.1 (this project) returns01
.It looks like the old PowerShell is just calculating
%V
as[Math]::Floor($_.DayOfYear/7)+1
, but I’m not sure where to report that.