From f13a8b5d7e64ba5ea9c16c7e5408c5ca722f8bf7 Mon Sep 17 00:00:00 2001 From: Tim Parkinson Date: Sat, 5 Aug 2017 10:45:01 +0100 Subject: [PATCH 1/8] Fix Get-Date -UFormat '%V' week number handling. Fix #4264 makes week number handling compliant with ISO-8601. --- .../commands/utility/GetDateCommand.cs | 3 ++- .../Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs index 5533721b5f6..193a8f6f3a9 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs @@ -459,7 +459,8 @@ private string UFormatDateString(DateTime dateTime) break; case 'V': - sb.Append((dateTime.DayOfYear / 7) + 1); + GregorianCalendar calendar = new GregorianCalendar(); + sb.Append(calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday)); break; case 'G': diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index fade58e6ece..fd979a673c4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -34,7 +34,12 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { } It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%" + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:0020532001/01/3000:00:00300030%" + } + + It "using -uformat 'V' produces correct ISO-8601 week number" { + Get-Date -Date 2017-01-01 -UFormat "%V" | Should Be 52 + Get-Date -Date 2017-01-08 -UFormat "%V" | Should Be 1 } It "Get-date works with pipeline input" { From 407eb51d0aed723eab58e812ad9efffef6415af9 Mon Sep 17 00:00:00 2001 From: Tim Parkinson Date: Mon, 4 Sep 2017 07:36:38 +0100 Subject: [PATCH 2/8] Revert "Fix Get-Date -UFormat '%V' week number handling." This reverts commit a5886cd5e419e07b884815f740e08b3c69513179. Solution was incorrect and needs a lot more work. --- .../commands/utility/GetDateCommand.cs | 3 +-- .../Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs index 193a8f6f3a9..5533721b5f6 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs @@ -459,8 +459,7 @@ private string UFormatDateString(DateTime dateTime) break; case 'V': - GregorianCalendar calendar = new GregorianCalendar(); - sb.Append(calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday)); + sb.Append((dateTime.DayOfYear / 7) + 1); break; case 'G': diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index fd979a673c4..fade58e6ece 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -34,12 +34,7 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { } It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:0020532001/01/3000:00:00300030%" - } - - It "using -uformat 'V' produces correct ISO-8601 week number" { - Get-Date -Date 2017-01-01 -UFormat "%V" | Should Be 52 - Get-Date -Date 2017-01-08 -UFormat "%V" | Should Be 1 + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%" } It "Get-date works with pipeline input" { From 38eb1f7160d9239eb1758e3f45d063de641aabc2 Mon Sep 17 00:00:00 2001 From: Tim Parkinson Date: Sat, 5 Aug 2017 10:45:01 +0100 Subject: [PATCH 3/8] Fix Get-Date -UFormat '%V' week number handling. Fix #4264 makes week number handling compliant with ISO-8601. --- .../commands/utility/GetDateCommand.cs | 3 ++- .../Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs index 5533721b5f6..193a8f6f3a9 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs @@ -459,7 +459,8 @@ private string UFormatDateString(DateTime dateTime) break; case 'V': - sb.Append((dateTime.DayOfYear / 7) + 1); + GregorianCalendar calendar = new GregorianCalendar(); + sb.Append(calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday)); break; case 'G': diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index fade58e6ece..fd979a673c4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -34,7 +34,12 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { } It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%" + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:0020532001/01/3000:00:00300030%" + } + + It "using -uformat 'V' produces correct ISO-8601 week number" { + Get-Date -Date 2017-01-01 -UFormat "%V" | Should Be 52 + Get-Date -Date 2017-01-08 -UFormat "%V" | Should Be 1 } It "Get-date works with pipeline input" { From f95283014e419670bb9523da46a8918ab1995853 Mon Sep 17 00:00:00 2001 From: Tim Parkinson Date: Mon, 4 Sep 2017 07:36:38 +0100 Subject: [PATCH 4/8] Revert "Fix Get-Date -UFormat '%V' week number handling." This reverts commit a5886cd5e419e07b884815f740e08b3c69513179. Solution was incorrect and needs a lot more work. --- .../commands/utility/GetDateCommand.cs | 3 +-- .../Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs index 193a8f6f3a9..5533721b5f6 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs @@ -459,8 +459,7 @@ private string UFormatDateString(DateTime dateTime) break; case 'V': - GregorianCalendar calendar = new GregorianCalendar(); - sb.Append(calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday)); + sb.Append((dateTime.DayOfYear / 7) + 1); break; case 'G': diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index fd979a673c4..fade58e6ece 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -34,12 +34,7 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { } It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:0020532001/01/3000:00:00300030%" - } - - It "using -uformat 'V' produces correct ISO-8601 week number" { - Get-Date -Date 2017-01-01 -UFormat "%V" | Should Be 52 - Get-Date -Date 2017-01-08 -UFormat "%V" | Should Be 1 + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%" } It "Get-date works with pipeline input" { From 59af68e72c6f6e13cd2138b58c179e7603dbbf52 Mon Sep 17 00:00:00 2001 From: Tim Parkinson Date: Sat, 5 Aug 2017 10:45:01 +0100 Subject: [PATCH 5/8] Fix Get-Date -UFormat '%V' week number handling. Fix #4264 makes week number handling compliant with ISO-8601. --- .../commands/utility/GetDateCommand.cs | 3 ++- .../Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs index 5533721b5f6..193a8f6f3a9 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs @@ -459,7 +459,8 @@ private string UFormatDateString(DateTime dateTime) break; case 'V': - sb.Append((dateTime.DayOfYear / 7) + 1); + GregorianCalendar calendar = new GregorianCalendar(); + sb.Append(calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday)); break; case 'G': diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index fade58e6ece..fd979a673c4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -34,7 +34,12 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { } It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%" + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:0020532001/01/3000:00:00300030%" + } + + It "using -uformat 'V' produces correct ISO-8601 week number" { + Get-Date -Date 2017-01-01 -UFormat "%V" | Should Be 52 + Get-Date -Date 2017-01-08 -UFormat "%V" | Should Be 1 } It "Get-date works with pipeline input" { From 7955192a9413d163eb1a67b3e7bdd1b7da9a7e30 Mon Sep 17 00:00:00 2001 From: Tim Parkinson Date: Mon, 4 Sep 2017 07:36:38 +0100 Subject: [PATCH 6/8] Revert "Fix Get-Date -UFormat '%V' week number handling." This reverts commit a5886cd5e419e07b884815f740e08b3c69513179. Solution was incorrect and needs a lot more work. --- .../commands/utility/GetDateCommand.cs | 3 +-- .../Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs index 193a8f6f3a9..5533721b5f6 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs @@ -459,8 +459,7 @@ private string UFormatDateString(DateTime dateTime) break; case 'V': - GregorianCalendar calendar = new GregorianCalendar(); - sb.Append(calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday)); + sb.Append((dateTime.DayOfYear / 7) + 1); break; case 'G': diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index fd979a673c4..fade58e6ece 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -34,12 +34,7 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { } It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:0020532001/01/3000:00:00300030%" - } - - It "using -uformat 'V' produces correct ISO-8601 week number" { - Get-Date -Date 2017-01-01 -UFormat "%V" | Should Be 52 - Get-Date -Date 2017-01-08 -UFormat "%V" | Should Be 1 + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%" } It "Get-date works with pipeline input" { From b1e4cf993b6f1b7b5d8bb8eba123bde95b680168 Mon Sep 17 00:00:00 2001 From: Tim Parkinson Date: Sat, 5 Aug 2017 10:45:01 +0100 Subject: [PATCH 7/8] Fix Get-Date -UFormat '%V' week number handling. Fix #4264 makes week number handling compliant with ISO-8601. --- .../commands/utility/GetDateCommand.cs | 3 ++- .../Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs index 5533721b5f6..193a8f6f3a9 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs @@ -459,7 +459,8 @@ private string UFormatDateString(DateTime dateTime) break; case 'V': - sb.Append((dateTime.DayOfYear / 7) + 1); + GregorianCalendar calendar = new GregorianCalendar(); + sb.Append(calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday)); break; case 'G': diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index fade58e6ece..fd979a673c4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -34,7 +34,12 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { } It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%" + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:0020532001/01/3000:00:00300030%" + } + + It "using -uformat 'V' produces correct ISO-8601 week number" { + Get-Date -Date 2017-01-01 -UFormat "%V" | Should Be 52 + Get-Date -Date 2017-01-08 -UFormat "%V" | Should Be 1 } It "Get-date works with pipeline input" { From a23b81ae9aaa747c93e77eee1b7eca44d8a8d1c8 Mon Sep 17 00:00:00 2001 From: Tim Parkinson Date: Mon, 4 Sep 2017 07:36:38 +0100 Subject: [PATCH 8/8] Revert "Fix Get-Date -UFormat '%V' week number handling." This reverts commit a5886cd5e419e07b884815f740e08b3c69513179. Solution was incorrect and needs a lot more work. --- .../commands/utility/GetDateCommand.cs | 3 +-- .../Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs index 193a8f6f3a9..5533721b5f6 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs @@ -459,8 +459,7 @@ private string UFormatDateString(DateTime dateTime) break; case 'V': - GregorianCalendar calendar = new GregorianCalendar(); - sb.Append(calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday)); + sb.Append((dateTime.DayOfYear / 7) + 1); break; case 'G': diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 index fd979a673c4..fade58e6ece 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Date.Tests.ps1 @@ -34,12 +34,7 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" { } It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:0020532001/01/3000:00:00300030%" - } - - It "using -uformat 'V' produces correct ISO-8601 week number" { - Get-Date -Date 2017-01-01 -UFormat "%V" | Should Be 52 - Get-Date -Date 2017-01-08 -UFormat "%V" | Should Be 1 + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%" } It "Get-date works with pipeline input" {