Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-Date -UFormat %W does not match reference implementation #20978

Open
5 tasks done
Tracked by #20982
brianary opened this issue Dec 30, 2023 · 0 comments · May be fixed by #20985
Open
5 tasks done
Tracked by #20982

Get-Date -UFormat %W does not match reference implementation #20978

brianary opened this issue Dec 30, 2023 · 0 comments · May be fixed by #20985
Labels
In-PR Indicates that a PR is out for the issue Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Comments

@brianary
Copy link
Contributor

Prerequisites

Steps to reproduce

Get-Date -UFormat %W

Currently, dateTime.DayOfYear / 7 is being used, but the code below is a better match. See Date conversion specifiers or strftime.

var startOfYearDayOfWeek = (int)(new DateTime(dateTime.Year, 1, 1)).DayOfWeek;
var adjustedDayOfYear = startOfYearDayOfWeek < 2 ? dateTime.DayOfYear + 7 : dateTime.DayOfYear;
var adjustedDayOfWeek = ((int)dateTime.DayOfWeek + 6) % 7;
sb.Append(((startOfYearDayOfWeek+adjustedDayOfYear-adjustedDayOfWeek)/7).ToString("00"));

Expected behavior

Based on running the `date -d $date +%W` as a reference implementation (see Environment for details).

PS> Get-Date 1999-01-01 -UFormat %W
00
PS> Get-Date 2000-02-14 -UFormat %W
07
PS> Get-Date 2001-03-29 -UFormat %W
13
PS> Get-Date 2002-05-12 -UFormat %W
18
PS> Get-Date 2003-06-25 -UFormat %W
25
PS> Get-Date 2004-08-07 -UFormat %W
31
PS> Get-Date 2005-09-20 -UFormat %W
38
PS> Get-Date 2006-11-03 -UFormat %W
44
PS> Get-Date 2007-12-17 -UFormat %W
51
PS> Get-Date 2009-01-29 -UFormat %W
04
PS> Get-Date 2010-03-14 -UFormat %W
10
PS> Get-Date 2011-04-27 -UFormat %W
17
PS> Get-Date 2012-06-09 -UFormat %W
23
PS> Get-Date 2013-07-23 -UFormat %W
29
PS> Get-Date 2014-09-05 -UFormat %W
35
PS> Get-Date 2015-10-19 -UFormat %W
42
PS> Get-Date 2016-12-01 -UFormat %W
48
PS> Get-Date 2018-01-14 -UFormat %W
02
PS> Get-Date 2019-02-27 -UFormat %W
08
PS> Get-Date 2020-04-11 -UFormat %W
14

Actual behavior

PS> Get-Date 1999-01-01 -UFormat %W
0
PS> Get-Date 2000-02-14 -UFormat %W
6
PS> Get-Date 2001-03-29 -UFormat %W
12
PS> Get-Date 2002-05-12 -UFormat %W
18
PS> Get-Date 2003-06-25 -UFormat %W
25
PS> Get-Date 2004-08-07 -UFormat %W
31
PS> Get-Date 2005-09-20 -UFormat %W
37
PS> Get-Date 2006-11-03 -UFormat %W
43
PS> Get-Date 2007-12-17 -UFormat %W
50
PS> Get-Date 2009-01-29 -UFormat %W
4
PS> Get-Date 2010-03-14 -UFormat %W
10
PS> Get-Date 2011-04-27 -UFormat %W
16
PS> Get-Date 2012-06-09 -UFormat %W
23
PS> Get-Date 2013-07-23 -UFormat %W
29
PS> Get-Date 2014-09-05 -UFormat %W
35
PS> Get-Date 2015-10-19 -UFormat %W
41
PS> Get-Date 2016-12-01 -UFormat %W
48
PS> Get-Date 2018-01-14 -UFormat %W
2
PS> Get-Date 2019-02-27 -UFormat %W
8
PS> Get-Date 2020-04-11 -UFormat %W
14

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

WSL Ubuntu details:

$ uname -a
Linux localhost 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Visuals

No response

@brianary brianary added the Needs-Triage The issue is new and needs to be triaged by a work group. label Dec 30, 2023
brianary added a commit to brianary/PowerShell that referenced this issue Jan 1, 2024
@brianary brianary linked a pull request Jan 1, 2024 that will close this issue
22 tasks
@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR Indicates that a PR is out for the issue label Jan 1, 2024
brianary added a commit to brianary/PowerShell that referenced this issue Jan 1, 2024
@kilasuit kilasuit added the WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module label Jan 2, 2024
brianary added a commit to brianary/PowerShell that referenced this issue Feb 9, 2024
brianary added a commit to brianary/PowerShell that referenced this issue Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In-PR Indicates that a PR is out for the issue Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants