Skip to content

Commit 40577cb

Browse files
JamesWTruheradityapatwardhan
authored andcommitted
Add the timezone offset correctly (PowerShell#4867)
It must be padded to 3 digits and prepended with either '-' or '+' An incorrectly formatted string will not be able to be converted back to a datetime
1 parent 65cf571 commit 40577cb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

test/powershell/engine/Cdxml/Cdxml.Tests.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ Describe "Cdxml cmdlets are supported" -Tag CI,RequireAdminOnWindows {
5959
$currentTimeZone = [System.TimeZoneInfo]::Local
6060

6161
# this date is simply the same one used in the test mof
62-
$UTCOffset = ($currentTimeZone.GetUtcOffset([datetime]::new(2008, 01, 01, 0, 0, 0))).TotalMinutes.ToString()
62+
# the minutes must be padded to 3 digits proceeded by a '+' or '-'
63+
# when east of UTC 0 we must add a '+'
64+
$offsetMinutes = ($currentTimeZone.GetUtcOffset([datetime]::new(2008, 01, 01, 0, 0, 0))).TotalMinutes
65+
$UTCOffset = "{0:+000;-000}" -f $offsetMinutes
6366
$testMof = $testMof.Replace("<UTCOffSet>", $UTCOffset)
6467
Set-Content -Path $testDrive\testmof.mof -Value $testMof
6568
$result = MofComp.exe $testDrive\testmof.mof

0 commit comments

Comments
 (0)