◐ Shell
clean mode source ↗

Fix ConvertTo-Json DateTime timezone test by KirtiRamchandani · Pull Request #27524 · PowerShell/PowerShell

PR Summary

Make the ConvertTo-Json DateTime ETS test independent of the machine's local timezone.

PR Context

The test parsed 2021-06-24T15:54:06.796999-07:00 into a local DateTime, then expected the compressed JSON to start with 2021-06-24. On machines at UTC+1 or later, that same instant serializes as the next local date, so the assertion fails even though ConvertTo-Json is behaving correctly.

This normalizes the fixture through DateTimeOffset.Parse(...).UtcDateTime and checks the exact UTC JSON string. The roundtrip assertion remains in place, so the test still verifies that DateTime is serialized as a scalar value rather than with ETS properties.

Fixes #27500

PR Checklist

Tests

  • Reproduced failure before the fix with Start-PSPester -Path ./test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Json.Tests.ps1 -UseNuGetOrg -SkipTestToolBuild -ThrowOnFailure
  • Start-PSPester -Path ./test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Json.Tests.ps1 -UseNuGetOrg -SkipTestToolBuild -ThrowOnFailure (222 passed, 1 pending)
  • git diff --check