Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ private string UFormatDateString(DateTime dateTime)
break;

case 'u':
sb.Append((int)dateTime.DayOfWeek);
int dayOfWeek = dateTime.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)dateTime.DayOfWeek;
sb.Append(dayOfWeek);
break;

case 'V':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,48 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" {
Get-Date -Date $date -UFormat %V | Should -BeExactly $week
}

# Using the same test cases as V for ISO week date component parity
It "using -uformat 'u' produces the correct output" -TestCases @(
@{date="1998-01-02"; dayOfWeek = "5"},
@{date="1998-01-03"; dayOfWeek = "6"},
@{date="2003-01-03"; dayOfWeek = "5"},
@{date="2004-01-02"; dayOfWeek = "5"},
Comment on lines +101 to +105
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clarify how you select the test values (whole list)?

Copy link
Contributor Author

@brianary brianary Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used the values from the previous test for %V, which is related, then added a couple recent dates that had led to discovering the bug. I'll add a comment to that effect, or else select some other dates.

@{date="2004-01-03"; dayOfWeek = "6"},
@{date="2005-01-01"; dayOfWeek = "6"},
@{date="2005-01-02"; dayOfWeek = "7"},
@{date="2005-12-31"; dayOfWeek = "6"},
@{date="2006-01-01"; dayOfWeek = "7"},
@{date="2006-01-02"; dayOfWeek = "1"},
@{date="2006-12-31"; dayOfWeek = "7"},
@{date="2007-01-01"; dayOfWeek = "1"},
@{date="2007-12-30"; dayOfWeek = "7"},
@{date="2007-12-31"; dayOfWeek = "1"},
@{date="2008-01-01"; dayOfWeek = "2"},
@{date="2008-12-28"; dayOfWeek = "7"},
@{date="2008-12-29"; dayOfWeek = "1"},
@{date="2008-12-30"; dayOfWeek = "2"},
@{date="2008-12-31"; dayOfWeek = "3"},
@{date="2009-01-01"; dayOfWeek = "4"},
@{date="2009-01-02"; dayOfWeek = "5"},
@{date="2009-01-03"; dayOfWeek = "6"},
@{date="2009-12-31"; dayOfWeek = "4"},
@{date="2010-01-01"; dayOfWeek = "5"},
@{date="2010-01-02"; dayOfWeek = "6"},
@{date="2010-01-03"; dayOfWeek = "7"},
@{date="2010-01-04"; dayOfWeek = "1"},
@{date="2014-01-03"; dayOfWeek = "5"},
@{date="2015-01-02"; dayOfWeek = "5"},
@{date="2015-01-03"; dayOfWeek = "6"},
@{date="2020-01-03"; dayOfWeek = "5"},
@{date="2025-01-03"; dayOfWeek = "5"},
@{date="2026-01-02"; dayOfWeek = "5"},
@{date="2026-01-03"; dayOfWeek = "6"},
@{date="2031-01-03"; dayOfWeek = "5"}
) {
param($date, $dayOfWeek)
Get-Date -Date $date -UFormat %u | Should -BeExactly $dayOfWeek
}

It "Passing '<name>' to -uformat produces a descriptive error" -TestCases @(
@{ name = "`$null" ; value = $null; errorId = "ParameterArgumentValidationErrorNullNotAllowed" }
@{ name = "empty string"; value = ""; errorId = "ParameterArgumentValidationErrorEmptyStringNotAllowed" }
Expand Down