Skip to content

Respect -ListAvailable:$false in Get-TimeZone#26463

Merged
iSazonov merged 1 commit intoPowerShell:masterfrom
yotsuda:fix/get-timezone-listavailable-26462
Nov 17, 2025
Merged

Respect -ListAvailable:$false in Get-TimeZone#26463
iSazonov merged 1 commit intoPowerShell:masterfrom
yotsuda:fix/get-timezone-listavailable-26462

Conversation

@yotsuda
Copy link
Contributor

@yotsuda yotsuda commented Nov 17, 2025

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.cs line 57: Changed if (this.ParameterSetName.Equals("ListAvailable", StringComparison.OrdinalIgnoreCase)) to if (ListAvailable)
  • Added test case in TimeZone.Tests.ps1 to verify -ListAvailable:$false returns only the current time zone

Testing

  • Added new test: "Call with -ListAvailable:$false returns current TimeZoneInfo (not list)"
  • The test verifies that -ListAvailable:$false returns 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

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 17, 2025
@iSazonov iSazonov self-assigned this Nov 17, 2025
@iSazonov iSazonov merged commit 11d154c into PowerShell:master Nov 17, 2025
36 of 37 checks passed
@yotsuda yotsuda deleted the fix/get-timezone-listavailable-26462 branch November 18, 2025 00:26
SIRMARGIN pushed a commit to SIRMARGIN/PowerShell that referenced this pull request Dec 12, 2025
kilasuit pushed a commit to kilasuit/PowerShell that referenced this pull request Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-ListAvailable:$false not respected in Get-TimeZone

2 participants