Respect -ListAvailable:$false in Get-TimeZone by yotsuda · Pull Request #26463 · PowerShell/PowerShell
PR Summary
This PR fixes the issue where -ListAvailable:$false is not respected in Get-TimeZone, causing it to behave the same as -ListAvailable:$true.
Fixes #26462
Related to #25242
PR Context
When -ListAvailable:$false is explicitly specified for Get-TimeZone, the cmdlet incorrectly returns all available time zones instead of returning only the current time zone. This occurs because the code checks ParameterSetName (a string) instead of checking the actual boolean value of the ListAvailable parameter.
This fix changes the condition from checking the parameter set name to directly checking the ListAvailable property value, ensuring that explicit $false values are properly respected.
Changes
- Modified
TimeZoneCommands.csline 57: Changedif (this.ParameterSetName.Equals("ListAvailable", StringComparison.OrdinalIgnoreCase))toif (ListAvailable) - Added test case in
TimeZone.Tests.ps1to verify-ListAvailable:$falsereturns only the current time zone
Testing
- Added new test: "Call with -ListAvailable:$false returns current TimeZoneInfo (not list)"
- The test verifies that
-ListAvailable:$falsereturns a single TimeZoneInfo object representing the current time zone - Pre-fix: Test fails (returns all 142 time zones instead of 1)
- Post-fix: Test passes (returns 1 current time zone as expected)
- All existing tests continue to pass
PR Checklist
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- 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
- This fix corrects incorrect behavior to match expected behavior; no documentation changes needed
- Not Applicable
- Testing - New and feature