Skip to content

[AzDev] Fix DateTime.Parse culture-sensitivity in Merge-DevPR#29343

Merged
VeryEarly merged 1 commit intoAzure:mainfrom
isra-fel:fix/datetime-parse-culture-invariant
Mar 31, 2026
Merged

[AzDev] Fix DateTime.Parse culture-sensitivity in Merge-DevPR#29343
VeryEarly merged 1 commit intoAzure:mainfrom
isra-fel:fix/datetime-parse-culture-invariant

Conversation

@isra-fel
Copy link
Copy Markdown
Member

Description

[DateTime]::Parse() in Merge-DevPullRequest uses the current system culture by default. On non-US locales (e.g., where the default date format is DD/MM/YYYY), parsing a US-formatted date string like 03/30/2026 21:57:01 throws a FormatException.

Fix

Pass [System.Globalization.CultureInfo]::InvariantCulture as the second argument to [DateTime]::Parse() at both call sites (lines 139 and 206 in GitHub.psm1), ensuring consistent parsing regardless of the user's locale.

Testing

Verified the fix resolves the MethodInvocationException when running Merge-DevPR -AllArchivePR -Approve on a non-US locale system.

Use InvariantCulture when parsing createdAt dates from GitHub API
to avoid FormatException on non-US locales where the default culture
does not recognize MM/dd/yyyy date format.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 31, 2026 00:02
@azure-client-tools-bot-prd
Copy link
Copy Markdown

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the AzDev PowerShell tooling to make Merge-DevPullRequest locale-independent when parsing PR createdAt timestamps returned from GitHub CLI.

Changes:

  • Use CultureInfo.InvariantCulture when parsing createdAt values at both call sites.
  • Keep the existing human-readable CreatedAt output format for table display and returned objects.

'Title' = $_.title
'CreatedBy' = $_.author.login
'CreatedAt' = [DateTime]::Parse($_.createdAt).ToString('M/d/yyyy h:mm:ss tt')
'CreatedAt' = [DateTime]::Parse($_.createdAt, [System.Globalization.CultureInfo]::InvariantCulture).ToString('M/d/yyyy h:mm:ss tt')
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToString('M/d/yyyy h:mm:ss tt') is still culture-sensitive: in .NET custom format strings, / and : are replaced by the current culture’s date/time separators, and tt is culture-specific. On non-US locales this can produce output that diverges from the README’s expected 6/10/2024 2:15:30 PM style. To make the displayed/returned CreatedAt consistent across locales, pass CultureInfo.InvariantCulture to ToString(...) (or escape the separators if you intend literal / and :).

Suggested change
'CreatedAt' = [DateTime]::Parse($_.createdAt, [System.Globalization.CultureInfo]::InvariantCulture).ToString('M/d/yyyy h:mm:ss tt')
'CreatedAt' = [DateTime]::Parse($_.createdAt, [System.Globalization.CultureInfo]::InvariantCulture).ToString('M/d/yyyy h:mm:ss tt', [System.Globalization.CultureInfo]::InvariantCulture)

Copilot uses AI. Check for mistakes.
'Title' = $_.title
'CreatedBy' = $_.author.login
'CreatedAt' = ([DateTime]::Parse($_.createdAt).ToString('M/d/yyyy h:mm:ss tt'))
'CreatedAt' = ([DateTime]::Parse($_.createdAt, [System.Globalization.CultureInfo]::InvariantCulture).ToString('M/d/yyyy h:mm:ss tt'))
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above: ToString('M/d/yyyy h:mm:ss tt') uses the current culture’s separators and AM/PM designators. If the cmdlet output is meant to be stable across locales (as implied by the README example), pass CultureInfo.InvariantCulture to ToString(...) so CreatedAt formatting doesn’t change per user locale.

Suggested change
'CreatedAt' = ([DateTime]::Parse($_.createdAt, [System.Globalization.CultureInfo]::InvariantCulture).ToString('M/d/yyyy h:mm:ss tt'))
'CreatedAt' = ([DateTime]::Parse($_.createdAt, [System.Globalization.CultureInfo]::InvariantCulture).ToString('M/d/yyyy h:mm:ss tt', [System.Globalization.CultureInfo]::InvariantCulture))

Copilot uses AI. Check for mistakes.
@isra-fel isra-fel changed the title Fix DateTime.Parse culture-sensitivity in AzDev Merge-DevPR [AzDev] Fix DateTime.Parse culture-sensitivity in Merge-DevPR Mar 31, 2026
@isra-fel isra-fel added this to the Az 15.6.0 (05/05/2026) milestone Mar 31, 2026
@VeryEarly VeryEarly merged commit dfe5517 into Azure:main Mar 31, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants