GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — #4750 Fix Get-Date -UFormat %u behavior by brianary · Pull Request #14549 · PowerShell/PowerShell

#4750 Fix Get-Date -UFormat %u behavior #14549

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.

Sign up for GitHub

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

Merged
Ilya (iSazonov) merged 4 commits into PowerShell:master from brianary:UFormat_u
Feb 4, 2021

Uh oh!

There was an error while loading. Please reload this page.

Merged

#4750 Fix Get-Date -UFormat %u behavior #14549

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
6594b78
#4750 Fix Get-Date -UFormat %u behavior
BrianL-STCU Jan 5, 2021
9e0bd61
Changes from PR feedback
BrianL-STCU Jan 6, 2021
ebea063
Readability change as discussed in PR
BrianL-STCU Jan 6, 2021
c7df635
Update src/Microsoft.PowerShell.Commands.Utility/commands/utility/Get…
brianary Feb 3, 2021
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

3 changes: 2 additions & 1 deletion 3 src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs
Show comments
View file
Open in desktop
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
42 changes: 42 additions & 0 deletions 42 test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1
Show comments
View file
Open in desktop
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 thread Outdated
Comment on lines 101 to 105

@iSazonov Ilya (iSazonov) Jan 6, 2021

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

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)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@brianary Brian Lalonde (brianary) Jan 6, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@{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
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.