You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document that the -as operator is (unexpectedly) culture-sensitive, in about_Type_Operators #3193
Casts, which - by design - always use the invariant culture, so that you can use something like the following, irrespective of the current culture:
[datetime] '12/30/2018'# OK, irrespective of current culture
By contrast, when using -as with a string as the LHS, culture-sensitive parsing is invariably applied:
'12/30/2018'-as [datetime] # OK *only* in culture en-US or similar# NO output ($null), because culture fr-FR (French) does not recognize this date format.
PS> [cultureinfo]::CurrentCulture ='fr-FR'; '12/30/2018'-as [datetime]
Unfortunately, the behavior of -as is internally inconsistent, because other types, such as [double], again is culture-invariant (I don't know what rules underlie this discrepancy):
PS> [cultureinfo]::CurrentCulture ='fr-FR'; '1,2.3'-as [double]
12,3# '1,2.3' was recognized, implying that the INVARIANT culture was used.
This surprising discrepancy is likely unintentional, but fixing it may be too much of a breaking change - see PowerShell/PowerShell#8129
Either way, it should be documented for the existing versions.
changed the title [-]Document that the -as operator is (unexpectedly) culture-sensitive in about_Type_Operators[/-][+]Document that the -as operator is (unexpectedly) culture-sensitive, in about_Type_Operators[/+]on Oct 27, 2018
Activity
[-]Document that the -as operator is (unexpectedly) culture-sensitive in about_Type_Operators[/-][+]Document that the -as operator is (unexpectedly) culture-sensitive, in about_Type_Operators[/+]Fixes #3193 - note datetime conversion (#5613)