Title: -as operator is unexpectedly selectively culture-sensitive, unlike casts · Issue #8129 · PowerShell/PowerShell · GitHub
Open Graph Title: -as operator is unexpectedly selectively culture-sensitive, unlike casts · Issue #8129 · PowerShell/PowerShell
X Title: -as operator is unexpectedly selectively culture-sensitive, unlike casts · Issue #8129 · PowerShell/PowerShell
Description: Related: #6989 Casts from strings use the invariant culture whenever the underlying type has a static ::Parse() method that accepts an IFormatProvider parameter. Surprisingly, the -as operator does not exhibit this behavior and instead e...
Open Graph Description: Related: #6989 Casts from strings use the invariant culture whenever the underlying type has a static ::Parse() method that accepts an IFormatProvider parameter. Surprisingly, the -as operator does...
X Description: Related: #6989 Casts from strings use the invariant culture whenever the underlying type has a static ::Parse() method that accepts an IFormatProvider parameter. Surprisingly, the -as operator does...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/8129
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"-as operator is unexpectedly selectively culture-sensitive, unlike casts","articleBody":"\u003csup>Related: #6989\u003c/sup>\r\n\r\n_Casts_ from _strings_ use the _invariant_ culture whenever the underlying type has a static `::Parse()` method that accepts an `IFormatProvider` parameter.\r\n\r\nSurprisingly, the `-as` operator does _not_ exhibit this behavior and instead exhibits _culture-sensitive_ behavior, but does so _inconsistently_.\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\n[cultureinfo]::CurrentCulture = 'fr-FR'\r\n\r\n[double] '1,2.3'\r\n'1,2.3' -as [double]\r\n\r\n[datetime] '10/20/2018 1:22:33 AM' # OK, invariant culture is used.\r\n'10/20/2018 1:22:33 AM' -as [datetime] # Yields $null, because the *current* culture is used.\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n```none\r\n12,3\r\n12,3\r\n\r\nsamedi 20 octobre 2018 01:22:33\r\nsamedi 20 octobre 2018 01:22:33\r\n```\r\n\r\nActual behavior\r\n---------------\r\n\r\n```none\r\n12,3\r\n12,3\r\nsamedi 20 octobre 2018 01:22:33\r\n# !! No output, because the string wasn't recognized as a date.\r\n```\r\n\r\nThat is, `-as [datetime]` only works with strings that are formatted according to the rules of the _current_ culture; `'20 octobre 2018 01:22:33' -as [datetime]` would work, for instance.\r\n\r\nBy contrast, `'1,2.3'` _was_ consistently interpreted according to the rules of the _invariant_ culture (where `,` is the grouping char., and `.` the decimal mark; with `fr-FR` in effect, the culture-sensitive `[double]::parse('1,2.3')` would fail).\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\nPowerShell Core 6.2.0-preview.1 on macOS 10.14\r\nPowerShell Core 6.2.0-preview.1 on Ubuntu 16.04.5 LTS\r\nPowerShell Core 6.2.0-preview.1 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.165)\r\nWindows PowerShell v5.1.17134.228 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.345)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2018-10-26T05:18:45Z","url":"https://github.com/PowerShell/PowerShell/issues/8129"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:03be50f1-806e-24a8-586e-16a83e8a28cb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 87CE:330210:15EEC5:1E161A:6AFD5DAD |
| html-safe-nonce | 8af195207a121de0a8da543f00cc516df3ad5554d91fe2eb3aff145f6ded8ad2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0NFOjMzMDIxMDoxNUVFQzU6MUUxNjFBOjZBRkQ1REFEIiwidmlzaXRvcl9pZCI6IjUxMjM5NzczNzU1NTMyNDg2ODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 171df50006b71874327a9cf7fc8b0085c290868b4f3f74bc28db81dc760c9665 |
| hovercard-subject-tag | issue:374230444 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/8129/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f1ffde754ce2a68a0bfc8046babbe46eae17d7869c9294edad336d234dd6d0b0/PowerShell/PowerShell/issues/8129 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f1ffde754ce2a68a0bfc8046babbe46eae17d7869c9294edad336d234dd6d0b0/PowerShell/PowerShell/issues/8129 |
| og:image:alt | Related: #6989 Casts from strings use the invariant culture whenever the underlying type has a static ::Parse() method that accepts an IFormatProvider parameter. Surprisingly, the -as operator does... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width