question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

-UFormat "%V" logic incorrect for 2021, counts based off calendar day instead of DOW

See original GitHub issue

Getting 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ReevesLcommented, Jan 11, 2021

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.

1reaction
brianarycommented, Jan 11, 2021

While Windows PowerShell (powershell.exe) 5.1 (and earlier) erroneously returns 2 for Get-Date 2021-01-08 -UFormat %V, PowerShell Core (pwsh.exe) 7.1 (this project) returns 01.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found