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
- PR has a meaningful title
- Summarized changes
- Make sure all
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header - This PR is ready to merge. If this PR is a work in progress, please open this as a Draft Pull Request and mark it as Ready to Review when it is ready to merge.
- Breaking changes
- None
- User-facing changes
- Not Applicable
- Testing - New and feature
- N/A; fixes existing test coverage
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